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.

STM32L010で「hello...」とシリアルに出力(Mbed)HAL(PA_4)(STM32)(LPUART)

Last updated at Posted at 2021-11-30

Mbed2のリビジョンは、143

目的
シリアル通信のテスト

image.png

いろいろ

シリアルに関しては、実質人気総合No1でいろいろ後でまとめないと(予定)

記事の人気ランキングcaa45040調べ(2021/11/28 sun)
1.stts751(秋月での販売終了 後継S-5851 アドレス違い)
2.Python(WS2812Bの事)
3.シリアル(通信の方)
4.ソフトウェアシリアル(あと、1ポートほしいと推論される)
5.ds1307(時計の事)
6.ソフトウェアシリアル受信
7.内蔵ADC、電圧 330xmV(10の割り算とレベルコンバートは、必見)
?.GP2Y0A21YK(根強い人気)

いろいろ2
外部から観測していると読者のほとんどが
東工大、高専に片寄っている
ただでstm32を配布しているからだと推論される。
(異論は、認める)




# include "mbed.h"


int main()
{

    wait_ms(2); //HAL_Delayが失敗する為

    //シリアルの構造体の定義
    UART_HandleTypeDef hlpuart1;

    //シリアルへのクロックの選択
    RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_LPUART1;
    PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1;
    HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);

    //シリアルへクロックの供給
    __HAL_RCC_LPUART1_CLK_ENABLE();
    __HAL_RCC_GPIOA_CLK_ENABLE();

    //シリアル用のGPIOの設定
    GPIO_InitTypeDef GPIO_InitStruct = {0};
    GPIO_InitStruct.Pin = GPIO_PIN_4;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF6_LPUART1;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    //シリアルの設定
    hlpuart1.Instance = LPUART1;
    hlpuart1.Init.BaudRate = 209700;
    hlpuart1.Init.WordLength = UART_WORDLENGTH_7B;
    hlpuart1.Init.StopBits = UART_STOPBITS_1;
    hlpuart1.Init.Parity = UART_PARITY_NONE;
    hlpuart1.Init.Mode = UART_MODE_TX_RX;
    hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
    hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
    hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
    HAL_HalfDuplex_Init(&hlpuart1);



    while(1) {


    HAL_UART_Transmit(&hlpuart1, (uint8_t *)"hello world\r\n", 13, 10);

    HAL_Delay(500);

    

    }

}



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?