OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 2381|回复: 1

UCOSII上USART2无法发送数据

[复制链接]

17

主题

46

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
262
金钱
262
注册时间
2016-9-9
在线时间
94 小时
发表于 2016-11-1 17:18:30 | 显示全部楼层 |阅读模式
1金钱
本帖最后由 xmlhttp 于 2016-11-1 17:22 编辑

用定时可以发送的数据,将其复制到ucos的任务了就发送不了数据了。
中断上的代码:
[mw_shl_code=c,true]void TIM3_IRQHandler(void){        
        u8 i;
        TIM_ClearITPendingBit(TIM3,TIM_IT_Update);
        GPIO_SetBits(GPIOG,GPIO_Pin_3);
        printf("发送数据成功!>>%d\r\n",countof(send_buf));
        for(i=0;i<countof(send_buf);i++){
                USART_SendData(USART2,send_buf);
                while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==Bit_RESET);
        }
        delay_ms(2);
        GPIO_ResetBits(GPIOG,GPIO_Pin_3);
}[/mw_shl_code]

Ucos任务代码:
[mw_shl_code=c,true]//数据发送任务
void ReadDATA_task(void *pdata){
        char send_buf[]={0x01,0x03,0x00,0x00,0x00,0x03,0x05,0xCB};
        u8 i;
        while(1){
                GPIO_SetBits(GPIOG,GPIO_Pin_3);        
                for(i=0;i<countof(send_buf);i++){                                                
                        USART_SendData(USART2,send_buf);
                        while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==Bit_RESET);
                }
                delay_ms(2);
                GPIO_ResetBits(GPIOG,GPIO_Pin_3);         
                printf("发送数据成功!>>%d\r\n",countof(send_buf));
                OSTimeDlyHMSM(0,0,0,1000);  //延时1s        
        }
}[/mw_shl_code]
其中定义的countof是
#define countof(a)   (sizeof(a) / sizeof(*(a)))
send_buf是
char send_buf[]={0x01,0x03,0x00,0x00,0x00,0x03,0x05,0xCB};
请问是什么原因呢?ucos中”发送数据成功!>>8“已经打印出来,就是收不到数据。


正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165516
金钱
165516
注册时间
2010-12-1
在线时间
2116 小时
发表于 2016-11-1 19:04:01 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-5-24 21:11

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表