LoginSignup
0
0

STM32C011とWS2812B(3個)でランダムに光らせる。(時代は、かわって、秋月でSTM32C011J4M7が売っている)

Last updated at Posted at 2024-01-30

参考

STM32C011とWS2812B(3個)でランダムに光らせる。(時代は、かわって、秋月でSTM32C011J4M7が売っている)

x ws2812bがなぜ3個なのかと言うと2,3個で電流が超えるらしい

x 微調整は、各自おこなうように!!
x 高速化も、各自おこなうように!!(動いているけど規格外(びみょうに遅い))

目的
GPIOのテスト

構成(古い)
windows 10 21H2
Arduino
1.8.19
STM32 MCU based boards 2.2.0

説明
WS2812Bの接続ピンは、PA8です。

いろいろ
STM32C011とSTM320G71の違い
まずROMが16KB+(かくれ16KB ?)から128KBになっている。
割り算つかい放題?
printf使い放題?
浮動小数点つかい放題
速度同じ64Mhz 倍速回路あり(PLL)
RAMも32KBらしい
そんなところ

o_cop913.jpg

o_cop911.jpg

プログラム




//GPIO_WS2812B_RAND_C011_1


//プロトタイプ宣言
void bit_on1();  //(1)ビット
void bit_off1(); //(0)ビット


//定義
//フルカラー(RGB)LEDの設定領域
int l[90]; //max30 led

int on1;  //ビットのオン
int off1; //ビットのオフ

//             12345678    12345678    12345678    12345678
int b8[] =  {0b10000000, 0b01000000, 0b00100000, 0b00010000,
             0b00001000, 0b00000100, 0b00000010, 0b00000001
            };


//フルカラー(RGB)LEDの点灯関数 引数は、バイト数
void ws_led(int num1)
{

  int led_b;  //バイトの一時

  //オンオフの設定
  //                    1111110000000000
  //                    5432109876543210
  on1  = GPIOA->ODR | 0b0000000100000000;
  off1 = GPIOA->ODR & 0b1111111011111111;

  //バイト数分だけループする
  for (int ii = 0; ii < num1; ii++) {

    //8ビット分送る
    led_b = l[ii]; //次の1バイト    
    int jj = 8;//カウンター
    while(jj != 0) { //8から0

      //ビット毎にオン、オフを送信
      if ( (led_b & 0x80)  ) {
        bit_on1();  //ビットが1     
      } else {
        bit_off1(); //ビットが0
      }//endif

      led_b = led_b << 1; //1ビットシフト 
      jj--; //1引く
    }//while 8bit

  }//for max30byt

}//ws_led


//初期化
void setup() {

  randomSeed( micros() ); //乱数の初期化

  //ピンの初期化
  pinMode(PA8, OUTPUT);

  //無限ループ
  while (1) {

    //debug
    //l[3*0+0] = 32;
    //l[3*0+1] = 10;
    //l[3*0+2] = 0;
    //
    //l[3*1+0] = 0;
    //l[3*1+1] = 20;
    //l[3*1+2] = 32;
    //
    //l[3*2+0] = 32;
    //l[3*2+1] = 30;
    //l[3*2+2] = 32;

    //ランダムの値の設定
    for (int ii = 0; ii < 9; ii++) {
      l[ii] = random(32);
    }//for

    //ws2812bへデータを送る
    ws_led(9);

    //0.1秒待つ
    delay(1000);

  } //while

}//setup


//メインループ
void loop() {
}//loop


// 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 
void bit_off1(){
   //0.3us 800khz

    GPIOA->ODR = on1;

    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;


    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
    GPIOA->ODR = off1;

    GPIOA->ODR = off1;
    //GPIOA->ODR = off1;
    //GPIOA->ODR = off1;
    //GPIOA->ODR = off1;
    //GPIOA->ODR = off1;
    //GPIOA->ODR = off1;
    //GPIOA->ODR = off1;

    //GPIOA->ODR = off1;
    //GPIOA->ODR = off1;

}//0.3us


// 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
void bit_on1(){
   //1us 800khz
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;

    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;
    GPIOA->ODR = on1;

    GPIOA->ODR = on1;
    GPIOA->ODR = on1;


    GPIOA->ODR = off1;

    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
    //GPIOA->ODR = off1;
    //GPIOA->ODR = off1;
    //GPIOA->ODR = off1;
    //GPIOA->ODR = off1;
    //GPIOA->ODR = off1;
    //GPIOA->ODR = off1;
    //GPIOA->ODR = off1;
    //GPIOA->ODR = off1;
}//1us



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