2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

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

Last updated at Posted at 2021-05-06

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

x mbedのリビジョンは、125

参考
STM32F303K8 & mbedでSoftwareSerialを実装する 【TX編】
https://qiita.com/YuseiIto/items/ddc15a77fd7b57ffa757

忙しい人よう
https://os.mbed.com/users/caa45040/code/serial_test_010_2/


#include "mbed.h"

//Serial pc(USBTX, USBRX); // tx, rx
//Serial pc(SERIAL_TX, SERIAL_RX); //767
//Serial pc(PA_2, PA_3); //010
//Serial pc(PA_9, PA_10); //010

//アナログ入力の設定
//AnalogIn adc_vbat(A3); //PA_4

#define UART_DELAY 96 //  1/9600

//仮想シリアルの出力ポート
//DigitalOut TX(PA_9);
DigitalOut TX(PA_2);

//仮想シリアルへの一文字出力 9600bps
int pc_putc(char ch) {
        
    TX=1;
    TX=0;//START
    wait_us(UART_DELAY);

    for(int ii=0;ii<8;ii++){
        TX=(ch>>ii)&1;
        wait_us(UART_DELAY);
    }; //for

    TX=1;//Stop
    wait_us(UART_DELAY);
             
    return(0);
    
} //pc_putc


int main() {

    //ポートをhiにする 初期化
    TX=1;
    
    //adcの読み込み 0から4096
    //int s = (adc_vbat.read_u16()>>4);

    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

//容量削減
void error(const char* format, ...){}



serial_test_010_2_2.jpg

serial_test_010_2.jpg

serial_test_010_2_3.jpg

serial_test_010_2_4.jpg

serial_test_010_2_5.jpg

serial_test_p1_2.jpg

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?