高中生
最后登录1970-1-1
在线时间 小时
注册时间2015-12-21
|
目前已完成将开发板的16进制数据通过485口打印到电脑上,(传感器串口配置要求是9600,8位数据位,偶检验位),但是改用开发板向传感器发相同的命令却没有数据返回,是不是我的串口配置有问题?
主函数
static void Delay ( __IO uint32_t nCount )
{
for ( ; nCount != 0; nCount -- );
}
uint8_t ch;
char chen[9];
char chen2[9];
char che[5];
int i;
uint16_t send_AHRSO[5]={0x01,0x05,0x00,0x23,0x50};
uint8_t ch;
static void delay_ms(u16 time)
{
u16 i=0;
while(time--)
{
i=12000;
while(i--){}
}
}
void USART_PutHEX(USART_TypeDef* USARTx,uint8_t Data)
{
USART_SendData(USARTx, Data);
while(USART_GetFlagStatus(USARTx,USART_FLAG_TXE)==RESET);
}
int SendUrt()
{
GPIO_SetBits(mac485REDE_PORT,mac485REDE_PIN);
USART_PutHEX(USART2,send_AHRSO[0]);
USART_PutHEX(USART2,send_AHRSO[1]);
USART_PutHEX(USART2,send_AHRSO[2]);
USART_PutHEX(USART2,send_AHRSO[3]);
USART_PutHEX(USART2,send_AHRSO[4]);
//USART_PutHEX(USART2,send_AHRSO[4]);
}
//char CH[];
int DisplayDemo()
{
/* í¨1yDT¸ÄGRAMμÄé¨Ãè·½Ïò£¬è»oóí¨1y¿′òo¾§ÇåÆáμÄ髿飬¾í¿éòÔÖaμàGRAMμÄêμ¼êé¨Ãè·½ÏòáË */
ILI9341_GramScan ( 1 );
ILI9341_Clear ( 0, 0, 240, 320, macBACKGROUND);
ILI9341_DispString_EN ( 0, 10, "This is a lcd demo to display ascii", macBACKGROUND, macRED );
}
/**
* @brief Ö÷oˉêy
* @param ÎT
* @retval ÎT
*/
extern int iup;
char Num[3];
int main ( void )
{
//char cStr [ 10 ];
//uint32_t ulCount;
uint8_t ch=0;
iup=0;
USART2_Config();
LED_GPIO_Config();
NVIC_Configuration();
LCD_Init (); //LCD 3õê¼»ˉ
DisplayDemo();
Num[2]='\0';
che[5]='\0';
while(1)
{
GPIO_ResetBits(mac485REDE_PORT,mac485REDE_PIN);
SendUrt();
Delay(1000);
if(iup>4)
{
iup=0;
Num[0]=che[2];
Num[1]=che[3];
// sprintf(chen,"%c",che);
// sprintf(chen2,"%c",Num);
ILI9341_DispString_EN ( 60, 60, che, macBACKGROUND, macRED );
ILI9341_DispString_EN ( 60, 100, Num, macBACKGROUND, macRED );
}
}
}
中断函数
void USART2_IRQHandler(void)
{
uint8_t ch;
//u8 temp=0;
extern char che[5];
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
{
//ch = USART1->DR;
ch=USART_ReceiveData(USART2);
GPIO_SetBits(mac485REDE_PORT,mac485REDE_PIN);
delay_ms(1);
che[iup]=ch;
iup++;
}
}
|
|