最近调试SMT8L151串口收发,遇到串口只能发送不能接收,原理图如下
12.jpg (29.89 KB, 下载次数: 0)
下载附件
2017-7-27 17:58 上传
void uartInit(u32 baudrate)
{
USART_Cmd(USART1 , DISABLE);
GPIO_Init(GPIOC,GPIO_Pin_2,GPIO_Mode_In_PU_No_IT); //串口 接 收
GPIO_Init(GPIOC,GPIO_Pin_3,GPIO_Mode_Out_PP_High_Slow); //串口发送
CLK_PeripheralClockConfig(CLK_Peripheral_USART1 , ENABLE); //使能USART1时钟
USART_Init(USART1, //设置USART1
baudrate, //流特率设置
USART_WordLength_8b, //数据长度设为8位
USART_StopBits_1, //1位停止位
USART_Parity_No, //无校验
(USART_Mode_Rx | USART_Mode_Tx)); //设置为发送接收双模式
//使能接收中断
USART_ITConfig(USART1, USART_IT_RXNE , ENABLE);
USART_Cmd(USART1 , ENABLE); //使能USART1模块
}
void putChar(u8 data)
{
USART_SendData8(USART1 , (u8)data); //向发送寄存器写入数据
while(USART_GetFlagStatus(USART1 , USART_FLAG_TXE) == RESET); //判断发送数据寄存器是否为空
}
发送没有问题 可以正常发送
INTERRUPT_HANDLER(USART1_RX_TIM5_CC_IRQHandler,28)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
u8 Res;
if(USART_GetITStatus(USART1,USART_IT_RXNE) == SET) //接收中断(接收到的数据必须是0x0d 0x0a结尾)
{
Res = USART_ReceiveData8(USART1); //(USART1->DR);//读 取接收到的数据
uartRecPro(Res);
USART_ClearITPendingBit(USART1,USART_IT_RXNE); //清除中断标志位
}
}
就是无法进入到接收里面去。
struct interrupt_vector const _vectab[] = {
{0x82, (interrupt_handler_t)_stext}, /* reset */
{0x82, NonHandledInterrupt}, /* trap */
{0x82, NonHandledInterrupt}, /* irq0 */
{0x82, NonHandledInterrupt}, /* irq1 */
{0x82, NonHandledInterrupt}, /* irq2 */
{0x82, NonHandledInterrupt}, /* irq3 */
{0x82, NonHandledInterrupt}, /* irq4 */
{0x82, NonHandledInterrupt}, /* irq5 */
{0x82, NonHandledInterrupt}, /* irq6 */
{0x82, NonHandledInterrupt}, /* irq7 */
{0x82, NonHandledInterrupt}, /* irq8 */
{0x82, NonHandledInterrupt}, /* irq9 */
{0x82, NonHandledInterrupt}, /* irq10 */
{0x82, EXTI3_IRQHandler}, /* irq11 */
{0x82, NonHandledInterrupt}, /* irq12 */
{0x82, NonHandledInterrupt}, /* irq13 */
{0x82, NonHandledInterrupt}, /* irq14 */
{0x82, EXTI7_IRQHandler}, /* irq15 */
{0x82, NonHandledInterrupt}, /* irq16 */
{0x82, NonHandledInterrupt}, /* irq17 */
{0x82, NonHandledInterrupt}, /* irq18 */
{0x82, NonHandledInterrupt}, /* irq19 */
{0x82, NonHandledInterrupt}, /* irq20 */
{0x82, NonHandledInterrupt}, /* irq21 */
{0x82, NonHandledInterrupt}, /* irq22 */
{0x82, NonHandledInterrupt}, /* irq23 */
{0x82, NonHandledInterrupt}, /* irq24 */
{0x82, TIM4_UPD_OVF_TRG_IRQHandler}, /* irq25 */
{0x82, NonHandledInterrupt}, /* irq26 */
{0x82, USART1_TX_TIM5_UPD_OVF_TRG_BRK_IRQHandler}, /* irq27 */
{0x82, USART1_RX_TIM5_CC_IRQHandler}, /* irq28 */
{0x82, NonHandledInterrupt}, /* irq29 */
};
一周热门 更多>