今天上午老师讲了UART通用异步串行通信带多线程
引脚:
UART(1) : (TX, RX) = (X9, X10) = (PB6, PB7) 连接 X9和X10两个引脚,自环测试。
pyb.UART类:
pyb.UART(bus, ...) UART.init(baudrate, bits=8, parity=None, stop=1, *, timeout=1000, flow=0, timeout_char=0, read_buf_len=64)
UART.deinit() UART.any() # 返回缓冲区中接收的字符数
下午用keil做了小灯闪亮的程序
#define RCC_BASE 0X40023800
#define GPINH_BASE 0x40021c00
#define RCC_AHB1ENR *(unsigned int *)(RCC_BASE+0X30)
#define GPIOH_MODER *(unsigned int *)(GPINH_BASE+0X00)
#define GPIOH_OTYPER *(unsigned int *)(GPINH_BASE+0X04)
#define GPIOH_OSPEEDR *(unsigned int *)(GPINH_BASE+0X08)
#define GPIOH_PUPDR *(unsigned int *)(GPINH_BASE+0X0C)
#define GPIOH_ODR *(unsigned int *)(GPINH_BASE+0X14)
void SystemInit(void){
}
void ccc()
{
RCC_AHB1ENR |=0X80;
GPIOH_MODER |=0x100000;
GPIOH_OTYPER |=0x00;
GPIOH_OSPEEDR =0x00;
GPIOH_PUPDR |=0x100000;
}
void delay(int n)
{
int i,j;
for(i=0;i<n;i++)
for(j=0;j<1200;j++);
int main(void)
{
ccc();
while (1)
{
GPIOH_ODR=0x00;
delay(1000);
GPIOH_ODR=0x400;
delay(1000);
}
}
1.配置时钟(所以外设使用前都需要使能相应时钟)2.外设初始化(根据芯片手册)3.编程
操作寄存器三步
1.通过芯片手册,找到要操作的外设寄存器。找到相应寄存器组的
基地址、偏移量、需操作位、以及要赋的值