我发送0X41 收到0X0B 发送0x0b收到0X0B 发送0bc 收到0XC7全部代码如下:
#include "stm32f10x.h"
void My_USART_Init();
void My_UART_Sent_Data(unsigned char dat);
int main()
{
My_USART_Init();
while(1)
{
My_UART_Sent_Data(0xbc);
}
}
具体寄存器,麻烦查阅一下STM32中文查考手册
void My_USART_Init()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
*(unsigned int*)(0X40013800 + 0x0c) = 0x0000200c; //8位数据位
*(unsigned int*)(0x40013800 + 0x10) = 0x00000000;
*(unsigned int*)(0x40013800 + 0x08) = 72000000 / 57600;//57600的波特率
*(unsigned int*)(0X40013800 + 0x0c) = 0x0000200c; //8位数据位
My_UART_Sent_Data(0xff); //我不确定空闲符是我自己发还是系统发,我觉得自己发一次应该不会有问题。
}
void My_UART_Sent_Data(unsigned char dat)
{
*(unsigned int*)(0x40013800 + 0x04) = dat;
while(!((*(unsigned int*)(0x40013800)) & (1 << 6)));
}
对了,非常感谢
一周热门 更多>