单片机代码
#include "stm32f1xx_hal.h"
#include "string.h"
#define W5500_CS_GPIO_Port GPIOB
#define W5500_CS_Pin GPIO_PIN_12
SPI_HandleTypeDef hspi2;
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI2_Init(void);
uint8_t W5500_ReadByte(void)
{
uint8_t byte;
HAL_SPI_Receive(&hspi2, &byte, 1, 10);
return byte;
}
void W5500_WriteByte(uint8_t byte)
{
HAL_SPI_Transmit(&hspi2, &byte, 1, 10);
}
void W5500_Select(void)
{
HAL_GPIO_WritePin(W5500_CS_GPIO_Port, W5500_CS_Pin, GPIO_PIN_RESET);
}
void W5500_Deselect(void)
{
HAL_GPIO_WritePin(W5500_CS_GPIO_Port, W5500_CS_Pin, GPIO_PIN_SET);
}
void W5500_WriteReg(uint16_t reg, const uint8_t *buf, uint16_t size)
{
W5500_Select();
W5500_WriteByte((reg >> 8) & 0xFF); // Write high byte of address
W5500_WriteByte(reg & 0xFF); // Write low byte of address
for (uint16_t i = 0; i < size; i++)
{ 文章来源:https://www.toymoban.com/news/detail-412343.html
W5500_Wr文章来源地址https://www.toymoban.com/news/detail-412343.html
到了这里,关于STMicroelectronics的STM32微控制器和WIZnet的W5500以太网通信单片机代码的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!