單片機代碼
?
#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++)
? ? { 文章來源:http://www.zghlxwxcb.cn/news/detail-412343.html
? ? ? ? W5500_Wr文章來源地址http://www.zghlxwxcb.cn/news/detail-412343.html
到了這里,關(guān)于STMicroelectronics的STM32微控制器和WIZnet的W5500以太網(wǎng)通信單片機代碼的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!