|
当时3种接口由IIC和EA切换,测试3种都ok,所以uart接口时可定是连IO口了,但是应该没有用到,下面io初始化
void USART3_PIN()
{
/* USART3 PIN */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
以下是我串口的程序、
void UART_WriteReg(unsigned char Address, unsigned char value)
{
volatile unsigned char EchoByte;
Address &= 0x3f; //code the first byte
USART3_SendData(Address);
EchoByte=USART3_ReceiveData();
USART3_SendData(value);
}
unsigned char UART_ReadReg(unsigned char Address)
{
volatile unsigned char RegVal=0;
RegVal =USART3_ReceiveData();
Address = (Address & 0x3f) | 0x80; //code the first byte
USART3_SendData(Address);
delay_us(850); //²»ÄÜÈ¡Ïû È¡ÏûRESET²»¹ý ̫С»á³öÏÖÊý¾Ý´íÎó
RegVal =USART3_ReceiveData();
return RegVal;
}
void USART3_SendData(unsigned char value)
{
USART_GetFlagStatus(USART3,USART_FLAG_TC);
USART_SendData(USART3, value);
while(USART_GetFlagStatus(USART3, USART_FLAG_TC)==0);
}
unsigned char USART3_ReceiveData(void)
{
unsigned char TEMP;
if(USART_GetFlagStatus(USART3,USART_FLAG_RXNE)==SET)
{
TEMP =USART_ReceiveData(USART3);
}
return TEMP;
}
图片是原理图,希望能帮到你!@ |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|