LoginSignup
1
1

More than 1 year has passed since last update.

STM32G031と(VSCode+STM32Cube)でI2Cスレーブで遊ぶ(受信)(STM32G031J6M6)HAL

Last updated at Posted at 2021-12-09

x プルアップ抵抗を忘れずに10kΩがおすすめ
x 過去ログを見よ->
x cubeMXは、disco-g0316
x VSCoedは、nucleo-g031

x 4ピンは、リセットを解除してGPIOにする
x シリアルの速度は、中途半端な209700bps

x SWDは、気持ち設定した。

目的
I2Cスレーブのテスト

参考

I2C_SLAVE_TEST1_031_1内を適当にコピー

o_con142.jpg

o_con143.jpg

o_con144.jpg

o_con145.jpg

o_con146.jpg

main内のwhile内






        uint8_t aRxBuffer[1] = {0};
        char *str1 = 0;
        //aRxBuffer[0] = 0 ;

        if(HAL_I2C_Slave_Receive(&hi2c2,(uint8_t*)aRxBuffer, 1, 1000) == HAL_OK) {
           str1="OK\r\n";
            
        } else {
           str1="NG\r\n";
            
        }
        
        //ステータスの表示
        HAL_UART_Transmit(&hlpuart1, (uint8_t *)str1, 4, 10);
        
        //I2Cスレーブの受信データの表示
        HAL_UART_Transmit(&hlpuart1, (uint8_t *)"\tRead A: ", 9, 10);
        uint8_t n1  = '0' + (aRxBuffer[0] % 10);
        uint8_t n10 = '0' + (aRxBuffer[0] / 10);
        HAL_UART_Transmit(&hlpuart1, &n10, 1, 10);
        HAL_UART_Transmit(&hlpuart1, &n1, 1, 10);
        HAL_UART_Transmit(&hlpuart1, (uint8_t *)"\r\n", 2, 10);

        HAL_Delay(200);//0.2秒待つ















I2C内



  hi2c2.Init.OwnAddress1 = 0x80;



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