/*
*@Note
USART Print debugging routine:
USART1_Tx(PA9).
This example demonstrates using USART1(PA9) as a print debug port output.
*/
#include "lcd.h"
#include "debug.h"
#include "string.h"
u8 yuyinBuffer[] = " ";
/* Global typedef */
#define Photo_SIZE 2000 // DMA buffer size
u8 PhotoBuffer[Photo_SIZE]={3};
u8 PhotoBuffer2[Photo_SIZE]={3};
u16 photopoint = 0;
uint16_t PhotoReadPos = 0; //接收缓冲区读指针
/* Global define */
/* Global Variable */
/*********************************************************************
* @fn main
*
* @brief Main program.
*
* @return none
*/
void USART1_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void USART1_IRQHandler(void)
{
uint8_t temp;
if(USART_GetITStatus(USART1, USART_IT_IDLE) != RESET)
{
uint16_t rxBufferEnd = Photo_SIZE - DMA_GetCurrDataCounter(DMA1_Channel5); //计算 DMA 数据尾的位置
uint16_t i = 0;
lcd_show_num(10, 90, DMA_GetCurrDataCounter(DMA1_Channel5), 3, 16);
if (PhotoReadPos == rxBufferEnd){
// 无数据,返回
}
else{
// while (PhotoReadPos!=rxBufferEnd && i < rxBufferEnd - PhotoReadPos){
// }
lcd_show_string(50, 160, 32,"cscs");
// lcd_show_num(50, 90, PhotoBuffer[1999], 3, 16);
// lcd_show_num(30, 90, PhotoBuffer[15], 3, 16);
lcd_show_num(90, 90, rxBufferEnd - PhotoReadPos, 3, 16);
lcd_show_num(70, 90, PhotoBuffer[6], 3, 16);
lcd_show_num(50, 90, PhotoBuffer[5], 3, 16);
}
memset(PhotoBuffer, 3, sizeof(PhotoBuffer));
temp = USART1->STATR;
temp = USART1->DATAR; //清USART_IT_IDLE标志
}
lcd_show_string(50, 120, 32,"cscs444");
}
void UART1_CFG(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_Initstrcuture;
//开启时钟
RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
/* USART6 TX-->C0 RX-->C1 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //RX,输入上拉
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200; // 波特率
USART_InitStructure.USART_WordLength = USART_WordLength_8b; // 数据位 8
USART_InitStructure.USART_StopBits = USART_StopBits_1; // 停止位 1
USART_InitStructure.USART_Parity = USART_Parity_No; // 无校验
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; // 无硬件流控
USART_InitStructure.USART_Mode = USART_Mode_Rx; //使能 RX 和 TX
NVIC_Initstrcuture.NVIC_IRQChannel = USART1_IRQn;
NVIC_Initstrcuture.NVIC_IRQChannelPreemptionPriority=2;
NVIC_Initstrcuture.NVIC_IRQChannelSubPriority =0;
NVIC_Initstrcuture.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_Initstrcuture);
USART_Init(USART1, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_IDLE, ENABLE);//开启相关中断
DMA_Cmd(DMA1_Channel5, ENABLE);
USART_Cmd(USART1, ENABLE); //开启UART
}
void DMA5_INIT(void)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
// RX DMA 初始化,环形缓冲区自动接收
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)(&USART1->DATAR);
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)PhotoBuffer; // 接收缓冲区
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; // 方向 : 外设 作为 源,即 内存 <- 外设
DMA_InitStructure.DMA_BufferSize = Photo_SIZE; // 缓冲区长度为 RXBUF_SIZE
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; // 循环模式,构成环形缓冲区
DMA_Init(DMA1_Channel5, &DMA_InitStructure);
}
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
SystemCoreClockUpdate();
Delay_Init();
USART_Printf_Init(115200);
lcd_init();
lcd_show_string(50, 0, 32,"Yuimerlin");
DMA5_INIT();
UART1_CFG();
USART_DMACmd(USART1,USART_DMAReq_Rx,ENABLE);
Delay_Ms(2000);
int mm = 0;
int num = 0;
//char buffer[10000]={"\0"};
lcd_set_color(BLACK,WHITE);
while(1)
{
mm+=1;
lcd_show_num(50, 60, mm, 3, 16);
delay_ms(2000);
}
}
我这个人问题比较多...占据了论坛不少资源,道个歉先...
以下是问题描述:
赤菟的板子,然后我想用usart1的rx接收数据,打算使用串口空闲中断,但是在烧录该代码之后,通过调试工具给usart1输入”123456“,却显示DMA_GetCurrDataCounter(DMA1_Channel5)为0,也就是没有数据,这是为什么呀