初步实现软件 I2C
This commit is contained in:
parent
db39c97cc4
commit
1458953f57
@ -1 +1 @@
|
|||||||
Subproject commit 0a6b8ee6aa4d3b5c4952458c3c7cc905acbf5f64
|
Subproject commit 3f6627255410641aa26a077891e2e87c20cbde37
|
||||||
@ -339,7 +339,7 @@
|
|||||||
<MiscControls></MiscControls>
|
<MiscControls></MiscControls>
|
||||||
<Define>USE_HAL_DRIVER, STM32F103x6</Define>
|
<Define>USE_HAL_DRIVER, STM32F103x6</Define>
|
||||||
<Undefine></Undefine>
|
<Undefine></Undefine>
|
||||||
<IncludePath>..\Core;..\Libraries\HAL_Lib\Inc;..\Libraries\SoftSPI_HAL_Lib;..\User\Main;..\System\sys;..\System\systick;..\System\uart;..\Hardware\led</IncludePath>
|
<IncludePath>..\Core;..\Libraries\HAL_Lib\Inc;..\Libraries\SoftSPI_HAL_Lib;..\Libraries\SoftI2C_HAL_Lib;..\User\Main;..\System\sys;..\System\systick;..\System\uart;..\Hardware\led</IncludePath>
|
||||||
</VariousControls>
|
</VariousControls>
|
||||||
</Cads>
|
</Cads>
|
||||||
<Aads>
|
<Aads>
|
||||||
@ -650,6 +650,21 @@
|
|||||||
</File>
|
</File>
|
||||||
</Files>
|
</Files>
|
||||||
</Group>
|
</Group>
|
||||||
|
<Group>
|
||||||
|
<GroupName>SoftI2C_HAL_Lib</GroupName>
|
||||||
|
<Files>
|
||||||
|
<File>
|
||||||
|
<FileName>softi2c_conf.h</FileName>
|
||||||
|
<FileType>5</FileType>
|
||||||
|
<FilePath>..\Libraries\SoftI2C_HAL_Lib\softi2c_conf.h</FilePath>
|
||||||
|
</File>
|
||||||
|
<File>
|
||||||
|
<FileName>softi2c.c</FileName>
|
||||||
|
<FileType>1</FileType>
|
||||||
|
<FilePath>..\Libraries\SoftI2C_HAL_Lib\softi2c.c</FilePath>
|
||||||
|
</File>
|
||||||
|
</Files>
|
||||||
|
</Group>
|
||||||
<Group>
|
<Group>
|
||||||
<GroupName>System</GroupName>
|
<GroupName>System</GroupName>
|
||||||
<Files>
|
<Files>
|
||||||
|
|||||||
@ -1,20 +1,21 @@
|
|||||||
/**
|
/**
|
||||||
* @file main.c
|
* @file main.c
|
||||||
* @author Myth
|
* @author Myth
|
||||||
* @version 0.2
|
* @version 0.3
|
||||||
* @date 2021.10.12
|
* @date 2021.10.12
|
||||||
* @brief 工程主函数文件
|
* @brief 工程主函数文件
|
||||||
* @details 初始化及主循环
|
* @details 初始化及主循环
|
||||||
* @note 此版本实现功能:
|
* @note 此版本实现功能:
|
||||||
* 串口回显,回显时 PC13 上的 LED 闪烁
|
* 串口回显,回显时 PC13 上的 LED 闪烁
|
||||||
* 软件 SPI
|
* 软件 I2C
|
||||||
|
* JTAG 已禁用,请使用 SWD 调试
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
#include "systick.h"
|
#include "systick.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
|
|
||||||
#include "softspi.h"
|
#include "softi2c.h"
|
||||||
|
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
|
|
||||||
@ -27,6 +28,7 @@ int main(void)
|
|||||||
Error_Handler(__FILE__, __LINE__); //错误处理
|
Error_Handler(__FILE__, __LINE__); //错误处理
|
||||||
}
|
}
|
||||||
SystemClock_Config(); //初始化系统时钟为 72MHz
|
SystemClock_Config(); //初始化系统时钟为 72MHz
|
||||||
|
DisableJTAG(); //禁用 JTAG
|
||||||
SysTick_Init(); //初始化 SysTick 和软件定时器
|
SysTick_Init(); //初始化 SysTick 和软件定时器
|
||||||
UART_Init(); //初始化串口
|
UART_Init(); //初始化串口
|
||||||
|
|
||||||
@ -34,30 +36,39 @@ int main(void)
|
|||||||
|
|
||||||
UART_BindReceiveHandle(COM1, Echo); //绑定 COM1 串口接收中断至 Echo 函数
|
UART_BindReceiveHandle(COM1, Echo); //绑定 COM1 串口接收中断至 Echo 函数
|
||||||
|
|
||||||
SoftSPI_TypeDef SoftSPI;
|
SoftI2C_TypeDef SoftI2C;
|
||||||
|
|
||||||
SoftSPI.SCLK_GPIO = GPIOB;
|
SoftI2C.SDA_GPIO = GPIOB;
|
||||||
SoftSPI.SCLK_Pin = GPIO_PIN_10;
|
SoftI2C.SDA_Pin = GPIO_PIN_3;
|
||||||
SoftSPI.MOSI_GPIO = GPIOA;
|
SoftI2C.SCL_GPIO = GPIOB;
|
||||||
SoftSPI.MOSI_Pin = GPIO_PIN_5;
|
SoftI2C.SCL_Pin = GPIO_PIN_4;
|
||||||
SoftSPI.MISO_GPIO = GPIOA;
|
SoftI2C.Delay_Time = 10;
|
||||||
SoftSPI.MISO_Pin = GPIO_PIN_4;
|
|
||||||
SoftSPI.SS_GPIO = GPIOA;
|
|
||||||
SoftSPI.SS_Pin = GPIO_PIN_6;
|
|
||||||
SoftSPI.Delay_Time = 10;
|
|
||||||
|
|
||||||
if (SoftSPI_Init(&SoftSPI) != HAL_OK) //初始化软件 SPI
|
if (SoftI2C_Init(&SoftI2C) != HAL_OK) //初始化软件 I2C
|
||||||
{
|
{
|
||||||
Error_Handler(__FILE__, __LINE__); //错误处理
|
Error_Handler(__FILE__, __LINE__); //错误处理
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t write[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
|
||||||
uint8_t read[10];
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
//程序主循环
|
//程序主循环
|
||||||
SoftSPI_WriteReadBuff(&SoftSPI, write, read, 10);
|
SoftI2C_Start(&SoftI2C);
|
||||||
Delay_us(100);
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user