我用232的程序改成485的程序了
用串口232运行就正常 用到485就怎么都用不了
跪求各位大侠帮帮忙看下程序哪里有问题 感激不尽…
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART3 Tx (PB.10) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure USART3 Rx (PB.11) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
//系统中断管理
void NVIC_Configuration(void)
{
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
}
//配置系统时钟,使能各外设时钟
void RCC_Configuration(void)
{
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA
|RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC
|RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE
|RCC_APB2Periph_ADC1 | RCC_APB2Periph_AFIO
|RCC_APB2Periph_SPI1, ENABLE );
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4 | RCC_APB1Periph_USART2
|RCC_APB1Periph_USART3|RCC_APB1Periph_TIM2
, ENABLE );
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
}
void USART3_SendByte(u16 Data)
{
while (!(USART3->SR & USART_FLAG_TXE));
USART3->DR = (Data & (uint16_t)0x01FF);
}
void USART3Write(u8* data,u16 len)
{
u16 i;
// DIR485_H ;
for (i=0; i<len; i++){
USART3_SendByte(data);
}
// Delay10us(1000);
// DIR485_L;
}
void USART3_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 115200 ;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART3, &USART_InitStructure);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
USART_Cmd(USART3, ENABLE);
/* DIR485_L; */
}
void USART3_IRQHandler(void)
{
u8 c;
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
{
c=USART3->DR;
USART3_SendByte(c);
}
}
void Init_All_Periph(void)
{
RCC_Configuration();
InitDis();
GPIO_Configuration();
NVIC_Configuration();
USART3_Configuration();
USART3Write((u8*)" USART_example ",sizeof(" USART_example "));
}
int main(void)
{
Init_All_Periph();
SendMessage();
while(1)
{
}
}
|