LoginSignup
0
0

More than 1 year has passed since last update.

STM32L010でI2C EEPROで遊ぶ3(連続書き込み)

Last updated at Posted at 2022-07-23

x Mbed2リビジョン125

目的
I2C EEPROMのテスト

通販コード K-12061

o_con588.jpg

読み込みテスト

o_con589.jpg



//SER_I2C_EEPROM_write_s_010_1

#include "mbed.h"

I2C i2c(PA_10, PA_9); //010

//#define S5851A 0x48
#define ADDR        ((0x50)<<1)   //  address


//四桁の変換
//#define DIV10(n) (((n*409)+((n*154)>>8))>>12)
int DIV10(int n)
{
    return    (((n*409)+((n*154)>>8))>>12)    ;
}
char data[16];
char *itoa9999(int d)
{

    data[4] = 0;
    data[3] = '0' + (  d - (DIV10(d) * 10)  );  // '0'+(d%10)
    d = DIV10(d);
    data[2] = '0' + (  d - (DIV10(d) * 10)  );  // '0'+(d%10)
    d = DIV10(d);
    data[1] = '0' + (  d - (DIV10(d) * 10)  );  // '0'+(d%10)
    data[0] = '0' +  DIV10(d);                  // '0'+(d/10)

    return (data);

}//itoa99

//仮想シリアルへの一文字出力 9600bps
DigitalOut TX(PA_2);
//DigitalIn  RX(PA_3);
#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


//文字列の表示 nana_seg
int pc_puts(char *str1)
{
    //文字の中身がゼロか
    while(*str1) {
        pc_putc( *str1 ++);
    } //while

    //戻り値
    return(0);
}//pc_puts

//連続書き込み先頭2バイトは、予約で無視される
//例 "@@1234"の場合は、"1234"が書き込まれる@@は、破壊される
//len1は、予約の2バイトも含む長さ
void eeprom_write_s(char *str1, int len1) {


    int ii=0;

    //アドレス
    //set address
    str1[0] =    ii >> 8   ;
    str1[1] =    ii & 0xff ;
    //pc_puts( itoa9999(data1[0]) );
    //pc_puts( "#" );
    //pc_puts( itoa9999(data1[1]) );
    //pc_puts( " " );
    //データ
    //str1[2] = ii;
    //書き込み
    i2c.write(ADDR, str1, len1); //addres 0

    pc_puts( "Write len=" );
    pc_puts( itoa9999(len1) );
    pc_puts("\r\n");

}//eeprom_write_s

int main()
{

//    char data1[8]; //バッファー

    pc_puts("\r\n<START>\r\n");


    pc_puts("eeprom_write_s\r\n");

    //             123456789012
    char buff[] = "@@0123456789";

    eeprom_write_s( buff, 12);

    //1秒待つ
    wait_ms(1000);

}//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