本帖最后由 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“已经打印出来,就是收不到数据。
|