2019-07-21 05:36发布
wxjhby 发表于 2019-1-9 16:17 用调试器看死在哪里了 [mw_shl_code=applescript,true]void RS485_Init(void) {
最多设置5个标签!
[mw_shl_code=c,true]void RS485_Init(void)
{
USART_InitTypeDef USART_Initstucture;
GPIO_InitTypeDef GPIO_Initstucture;
NVIC_InitTypeDef NVIC_Initstuctrue;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_USART1,ENABLE);
GPIO_Initstucture.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Initstucture.GPIO_Pin=GPIO_Pin_9;
GPIO_Initstucture.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_Initstucture);
GPIO_Initstucture.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Initstucture.GPIO_Pin=GPIO_Pin_10;
GPIO_Init(GPIOA,&GPIO_Initstucture);
GPIO_Initstucture.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Initstucture.GPIO_Pin=GPIO_Pin_8;
GPIO_Initstucture.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_Initstucture);
USART_Initstucture.USART_BaudRate=9600;
USART_Initstucture.USART_HardwareFlowControl=USART_WordLength_8b;
USART_Initstucture.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
USART_Initstucture.USART_Parity=USART_Parity_No;
USART_Initstucture.USART_StopBits=USART_StopBits_1;
USART_Init(USART1,&USART_Initstucture);
USART_Cmd(USART1,ENABLE);
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
NVIC_Initstuctrue.NVIC_IRQChannel=USART1_IRQn;
NVIC_Initstuctrue.NVIC_IRQChannelCmd=ENABLE;
NVIC_Initstuctrue.NVIC_IRQChannelPreemptionPriority=0;
NVIC_Initstuctrue.NVIC_IRQChannelSubPriority=1;
NVIC_Init(&NVIC_Initstuctrue);
GPIO_ResetBits(GPIOA,GPIO_Pin_8);
}
void USART1_IRQHandler(void)
{
u8 res;
if(USART_GetITStatus(USART1,USART_IT_RXNE)!=RESET)
{
res=USART_ReceiveData(USART1);
if((USART_RX_STA&0X8000)==0)
{
if(USART_RX_STA&0X4000)
{
if(res!=0X0a)USART_RX_STA=0;
else USART_RX_STA|=0X8000;
}
else
{
if(res==0x0d)USART_RX_STA|=0X4000;
else
{
USART_RX_BUF[USART_RX_STA&0X3FFF]=res;
USART_RX_STA++;
if(USART_RX_STA>(USART_REC_LEN-1))USART_RX_STA=0;
}
}
}
}
}
void RS485_Send_Data(u8 *buf,u8 len)
{
u8 t;
GPIO_SetBits(GPIOA,GPIO_Pin_8);
for(t=0;t<len;t++)
{
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
USART_SendData(USART1,buf[t]);
}
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
GPIO_ResetBits(GPIOA,GPIO_Pin_8);
}
还是死在NVIC_Init这里 这是全部的代码
一周热门 更多>