0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

STM32F103C8でWS2812Bを光らせる。(Arduino)

Last updated at Posted at 2021-06-10

x まだ、ためしていないけど動くはず6/10
x 動きました。6/10 (結果は、ページの最後へ)
x STM32L010とSTM32G031は、まだ、いろいろなボードが
あまり出てこず、環境がほぼ、固定されているが
STM32F103は、一般的によく利用されているので
環境がバラバラです。その為にGPIOの速度の影響を受けます。
めんどうなので適当にイジッテください。
x光らない時の調整方法、現状は、実測でoff_bitは、0.3usと
on_bitは、1usに人力を使った力業で調整してあります。
空白(0)(LOW)は、あまり影響を受けないとなんかに書いてありました。
on_bitは、長いので誤作動の確率は、低いと推論できます。
よつて、off_bitとon_bitの区別が付かなくなるのは、一般的に
off_bitが長いと推論できます。
で、その事からoff_bitを短くします。
1が連続する誤作動は、off_bitが短い事が推論できます。off_bitを
長くします。

目的
GPIOのテスト

構成
windows 10 20H2
Arduino
1.8.13(Windows Store 1.8.42.0)
STM32duino 1.9.0

BluePill F103C8

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

参考




int l[90]; //max30 led

void bit_on1();
void bit_off1();

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

int ws_led(int num1)
{
    int on_off;

    //__disable_irq(); // disable interrupt
    //__enable_irq(); // enable interrupt

    //GPIO bkup
    //int g_bk  = GPIOA->ODR;


    for(int ii=0;ii<num1;ii++){
        //pc.printf("  -%d\t%d\r\n",ii,l[ii]); //303

        //8ビット分送る
        for(int jj=0;jj<8;jj++){
            //pc.printf("  -%d\r\n",jj); //303

            on_off = l[ii] & b8[jj];

            if( on_off == 0 ){
                //ビットが0
                //pc.printf("0"); //303
                bit_off1();
            } else {
                //ビットが1 
                //pc.printf("1"); //303
                bit_on1();
            }//endif

        }//for 8bit


    }//for max30byt

    //__disable_irq(); // disable interrupt
    //__enable_irq(); // enable interrupt

    //GPIO bkup
    //GPIOA->ODR = g_bk;

    return(0);
}


// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(PA7, OUTPUT);

    l[0] = 31;
    l[1] = 32;
    l[2] = 33;

    ws_led(3);

}//main

                      //     65432109876543210
    int on1  = GPIOA->ODR | 0b0000000010000000;
    int off1 = GPIOA->ODR & 0b1111011101111111;

// the loop function runs over and over again forever
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 = 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;
    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
    GPIOA->ODR = off1;
}


// 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 = 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;

}




gpio_ws2812b_103.jpg

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?