LoginSignup
0
0

More than 1 year has passed since last update.

STM32L010とDS1307で時計プログラム(ソフトウェアシリアル出力)

Last updated at Posted at 2022-08-08

x リビジョンの変え方がわかる人よう
x Mbed2リビジョン125

x 時間合わせは、別

目的
RTCのテスト
時間合わせが人気があったから

調査目的で引用
原文を確認の事

o_con625.jpg

o_con627.jpg


//i2c_ds1307_S_SER_010_1

#include "mbed.h"

//仮想シリアルへの一文字出力 9600bps
DigitalOut TX(PA_2);
#define UART_DELAY 101 //  1/9600 98-105
int pc_putc(char ch)
{
    TX=1;
    TX=0;//Start
    wait_us(UART_DELAY);

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

    TX=1;//Stop
    wait_us(UART_DELAY);

    return(0);
} //pc_putc

//メイン関数
int main()
{
    I2C i2c(PA_10, PA_9); //010

    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_ms(1000);
    }//while
}//main

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





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