STM32空閒中斷 DMA解決接收不定長資料問題

2021-08-02 19:30:00 字數 1669 閱讀 6935

串列埠的中斷型別:

#define usart_it_pe                          ((uint16_t)0x0028)

#define usart_it_txe ((uint16_t)0x0727)

#define usart_it_tc ((uint16_t)0x0626)

#define usart_it_rxne ((uint16_t)0x0525)

#define usart_it_idle ((uint16_t)0x0424)

#define usart_it_lbd ((uint16_t)0x0846)

#define usart_it_cts ((uint16_t)0x096a)

#define usart_it_err ((uint16_t)0x0060)

#define usart_it_ore ((uint16_t)0x0360)

#define usart_it_ne ((uint16_t)0x0260)

#define usart_it_fe ((uint16_t)0x0160)

usart_it_pe 奇偶錯誤中斷

usart_it_txe傳送中斷

usart_it_tc 傳輸完成中斷

usart_it_rxne 接收中斷

usart_it_idle 空閒匯流排中斷

usart_it_lbd lin中斷檢測中斷

usart_it_cts cts中斷

usart_it_err 錯誤中斷

該程式中用到的就是串列埠的空閒中斷:

當匯流排是乙個位元組週期內沒有收到資料時觸發

串列埠的配置如下:

void uart_init(u32 bound)
串列埠中斷配置:

void usart1_irqhandler(void)                 

}

dma配置:

void mydma_config(dma_channel_typedef* dma_chx,u32 cpar,u32 cmar,u16 ***tr)

主函式中需要進行的配置:

mydma_config(dma1_channel5,(u32)&usart1->dr,(u32)usart_rx_buf,32);//傳輸方向設定為usart1->dr到usart_rx_buf 傳輸大小為32位元組

usart_dmacmd(usart1,usart_dmareq_rx,enable);//允許dma請求

dma_cmd(dma1_channel5,enable);

當標誌為recok位1時表示接受完成  在主函式中等待recok位1就可以了

STM32空閒中斷 DMA解決接收不定長資料問題

串列埠的中斷型別 cpp view plain copy define usart it pe uint16 t 0x0028 define usart it txe uint16 t 0x0727 define usart it tc uint16 t 0x0626 define usart it...

stm32 利用DMA 串列埠空閒中斷接受任意長資料

二 串列埠空閒中斷 三 糾正 在進行stm32開發時,有時會遇到這種情況 需要在裝置間進行資料傳輸,由於stm32串列埠rdr和tdr暫存器都是8位有效的,我們往往需要定義傳輸協議 如一幀資料中,包含包含幀頭 幀id 資料幀 校驗幀等若干8位資料 我們希望可以一次收到一幀資料,並進行解碼操作。利dm...

關於STM32空閒中斷

有一次做乙個東西,為了盡量不占用cpu的處理資料時間,所以就使用dma接收串列埠的資料,但是呢問題來了.怎麼樣才能確定接收到了一條完整的資料了,我們都知道只要開啟dma 那傢伙就不停的把接收的資料放到我們指定的地方.只要接收到一條完整的資料我就該去處理了 關於空閒中斷,就是說每接收到一條完整的資料就...