86 lines
1.8 KiB
C
Raw Normal View History

2021-10-12 14:23:45 +08:00
/**
* @file main.c
* @author Myth
2021-10-12 23:38:04 +08:00
* @version 0.3
2021-10-12 14:23:45 +08:00
* @date 2021.10.12
* @brief
* @details
* @note
* PC13 LED
2021-10-12 23:38:04 +08:00
* I2C
* JTAG 使 SWD
2021-10-12 14:23:45 +08:00
*/
#include "sys.h"
#include "systick.h"
#include "uart.h"
2021-10-12 23:38:04 +08:00
#include "softi2c.h"
2021-10-12 14:23:45 +08:00
#include "led.h"
void Echo(uint8_t byte);
int main(void)
{
if (HAL_Init() != HAL_OK) //初始化 HAL 库
{
Error_Handler(__FILE__, __LINE__); //错误处理
}
SystemClock_Config(); //初始化系统时钟为 72MHz
2021-10-12 23:38:04 +08:00
DisableJTAG(); //禁用 JTAG
2021-10-12 14:23:45 +08:00
SysTick_Init(); //初始化 SysTick 和软件定时器
UART_Init(); //初始化串口
LED_Init(); //初始化 LED
UART_BindReceiveHandle(COM1, Echo); //绑定 COM1 串口接收中断至 Echo 函数
2021-10-12 23:38:04 +08:00
SoftI2C_TypeDef SoftI2C;
2021-10-12 18:08:20 +08:00
2021-10-12 23:38:04 +08:00
SoftI2C.SDA_GPIO = GPIOB;
SoftI2C.SDA_Pin = GPIO_PIN_3;
SoftI2C.SCL_GPIO = GPIOB;
SoftI2C.SCL_Pin = GPIO_PIN_4;
SoftI2C.Delay_Time = 10;
2021-10-12 18:08:20 +08:00
2021-10-12 23:38:04 +08:00
if (SoftI2C_Init(&SoftI2C) != HAL_OK) //初始化软件 I2C
2021-10-12 18:08:20 +08:00
{
Error_Handler(__FILE__, __LINE__); //错误处理
}
2021-10-12 14:23:45 +08:00
while (1)
{
//程序主循环
2021-10-12 23:38:04 +08:00
SoftI2C_Start(&SoftI2C);
SoftI2C_WriteByte(&SoftI2C, 0x10);
SoftI2C_WaitAck(&SoftI2C);
SoftI2C_WriteByte(&SoftI2C, 0x22);
SoftI2C_WaitAck(&SoftI2C);
SoftI2C_WriteByte(&SoftI2C, 0x33);
SoftI2C_WaitAck(&SoftI2C);
SoftI2C_WriteByte(&SoftI2C, 0x44);
SoftI2C_WaitAck(&SoftI2C);
SoftI2C_Stop(&SoftI2C);
Delay_us(1000);
2021-10-12 14:23:45 +08:00
}
return 1;
}
/**
* @brief
* @param byte:
*/
void Echo(uint8_t byte)
{
LED1_Slow_Toggle;
UART_SendChar(COM1, byte);
}