LoginSignup
0
0

More than 1 year has passed since last update.

STM32G031とDS1307で時計プログラム(ソフトウェアシリアル出力100bps)(I2C i2c(PA_12, PA_11);)

Last updated at Posted at 2022-08-13

x 過去ログを見よ
x PA_0をOBでGPIOに出来る人むけ
x STM32G031は、秋月で売っているSTM32G031J6M6の事

目的
秋月のDS1307ZN+T&R I-06950

o_con668.jpg

o_con669.jpg

o_con670.jpg

o_con671.jpg

o_con672.jpg



//i2c_ds1307_S_SER_031_1

#include "mbed.h"

DigitalOut TX1(PA_0);


//仮想シリアルへの一文字出力 1000bps
// 10 100bps
//  5
//  2
//  1 1000bps
int pc_putc(char ch)
{
    TX1=1;
    TX1=0;//Start
    wait_us(1000*10);

    for(int ii=0; ii<8; ii++) { //Data x 8
        TX1=(ch>>ii)&1;
        wait_us(1000*10);
    }; //for

    TX1=1;//Stop
    wait_us(1000*10);

    return(0);
} //pc_putc

//        sda   scl
I2C i2c(PA_12, PA_11); //010

int main() {

    char data_read[7]; //リードバッファー

    while(1) {

        //時間の読み込み
        i2c.write( (0xD0), "\000", 1);
        i2c.read(  (0xD0) | 1, data_read, 7);

        ///時間の表示
        pc_putc( '0'+(data_read[2] >> 4)  );
        pc_putc( '0'+(data_read[2] & 0xf) );
        pc_putc( '.' );
        pc_putc( '0'+(data_read[1] >> 4)  );
        pc_putc( '0'+(data_read[1] & 0xf) );
        pc_putc( '.' );
        pc_putc( '0'+(data_read[0] >> 4)  );
        pc_putc( '0'+(data_read[0] & 0xf) );
        pc_putc('\r');
        pc_putc('\n');

        // 1秒待つ
        wait_us(1000*10);
  
    }//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