LoginSignup
0
0

More than 1 year has passed since last update.

STM32L010のソフトウェアシリアルでHello Worldと出力 1200bps TX PA2 STM32 HAL

Last updated at Posted at 2021-09-11

目的
つくれそうだから作ってみた。
通信がづれる時はUART_DELAYの値を1足したり1引いたりして調整してね

x mbedのリビジョンは、143

h_con62.jpg

h_con61.jpg



#include "mbed.h"

#define UART_DELAY 832 //  1/1200

#define DW(AAA,BBB)  HAL_GPIO_WritePin(GPIOA,AAA,BBB)

GPIO_PinState bi1[]={GPIO_PIN_RESET,GPIO_PIN_SET};


//仮想シリアルへの一文字出力 9600bps
int pc_putc(char ch) {

    DW(GPIO_PIN_2,GPIO_PIN_SET);
    DW(GPIO_PIN_2,GPIO_PIN_RESET);//START
    wait_us(UART_DELAY);

    for(int ii=0;ii<8;ii++){          
        DW(GPIO_PIN_2, bi1[  ( (ch>>ii)&1 )  ]);
        wait_us(UART_DELAY);
    }; //for

    DW(GPIO_PIN_2,GPIO_PIN_SET);//Stop
    wait_us(UART_DELAY);

    return(0);

} //pc_putc


int main() {

    //ポートをhiにする 初期化
  __HAL_RCC_GPIOA_CLK_ENABLE(); 
  GPIO_InitTypeDef GPIO_InitStruct = {0}; 
  GPIO_InitStruct.Pin = GPIO_PIN_2;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, GPIO_PIN_SET);

    char *ss1; //文字のポインター
    int ii; //ループカウンター

    //無限ループ
    while(1) {

        ss1="Hello World !\r\n";
        ii=0; //ループカウンター
        while(ss1[ii]!=0){

            //一文字出力
            pc_putc(ss1[ii]);ii++;

        } //while

        //1秒の待ち
        wait_ms(1000);

    } //while

} //main





0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0