LoginSignup
0
0

More than 1 year has passed since last update.

STM32G031のmbed-osでのHT16K33(I2C)でナイトライダー HAL

Last updated at Posted at 2022-08-10

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

目的
最軽量化
I2Cのテスト
PA_0(4ピン)をLチカする。

1.SCLとSDAを接続、プルアップも忘れずに
2.電源の接続
3.下記のソースコードを書き込む
4.コンパイル実行で表示されたら終了
5.おわり

o_con646.jpg

関連


//HAL_HT16K33_031_1


#include "mbed.h"

#define ADDR        (0x70<<1)  //  address

int main() {

    __HAL_RCC_GPIOA_CLK_ENABLE();

    GPIO_InitTypeDef GPIO_InitStruct = {0};

    GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF6_I2C2;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_0;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);


    __HAL_RCC_I2C2_CLK_ENABLE();

    I2C_HandleTypeDef hi2c2;

    hi2c2.Instance = I2C2;
    hi2c2.Init.Timing = 0x10707DBC;
    hi2c2.Init.OwnAddress1 = 0;
    hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
    hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
    hi2c2.Init.OwnAddress2 = 0;
    hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
    hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
    hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
    HAL_I2C_Init(&hi2c2);    

    HAL_I2CEx_ConfigAnalogFilter(&hi2c2, I2C_ANALOGFILTER_ENABLE);

    HAL_I2CEx_ConfigDigitalFilter(&hi2c2, 0);


    uint8_t buf[16];

    buf[0]=0x21;
    HAL_I2C_Master_Transmit(&hi2c2, ADDR, buf, 1, 3000);HAL_Delay(1);

    buf[0]=0x81;
    HAL_I2C_Master_Transmit(&hi2c2, ADDR, buf, 1, 3000);HAL_Delay(1);

    buf[0]=0xef;
    HAL_I2C_Master_Transmit(&hi2c2, ADDR, buf, 1, 3000);HAL_Delay(1);

    for(int ii=0;ii<16;ii++){
        buf[0]=ii;
        buf[1]=0x00;
        HAL_I2C_Master_Transmit(&hi2c2, ADDR, buf, 2, 3000);HAL_Delay(1);
    }//for

    while(1) {

        for(int ii=0;ii<8;ii++){

            buf[0]=0;
            buf[1]= (1<<ii);
            HAL_I2C_Master_Transmit(&hi2c2, ADDR, buf, 2, 3000);HAL_Delay(600);

            HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);
            HAL_Delay(200);
            HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);
            HAL_Delay(200);

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