void SPI1_1B_WR(uint32_t addr, uint32_t data) { uint32_t addr_real = addr << 8; //addr_real[31:0] = {addr[31:8], 8'h00} uint32_t wdata = 0x5a000000; //int32_t spi_setup_cmd_addr(SPI_TypeDef *spi, uint32_t cmd, uint32_t cmdlen, uint32_t addr, uint
时间: 2023-08-12 22:01:52 浏览: 93
SPI.rar_singhbb_spi_spi 读寄存器_spi读写_spi读函数
5星 · 资源好评率100%
32_t addrlen)
{
// Configure SPI1 for write operation
SPI1->CR1 |= SPI_CR1_SPE; // Enable SPI1
// Send command and address
SPI1->DR = cmd; // Command
while (!(SPI1->SR & SPI_SR_TXE)); // Wait for transmit buffer empty
SPI1->DR = (addr >> 24) & 0xFF; // Address MSB
while (!(SPI1->SR & SPI_SR_TXE)); // Wait for transmit buffer empty
SPI1->DR = (addr >> 16) & 0xFF; // Address Byte 2
while (!(SPI1->SR & SPI_SR_TXE)); // Wait for transmit buffer empty
SPI1->DR = (addr >> 8) & 0xFF; // Address Byte 1
while (!(SPI1->SR & SPI_SR_TXE)); // Wait for transmit buffer empty
SPI1->DR = addr & 0xFF; // Address LSB
while (!(SPI1->SR & SPI_SR_TXE)); // Wait for transmit buffer empty
// Send data
SPI1->DR = data; // Data
while (!(SPI1->SR & SPI_SR_TXE)); // Wait for transmit buffer empty
// Wait for transfer complete
while (SPI1->SR & SPI_SR_BSY);
// Disable SPI1
SPI1->CR1 &= ~SPI_CR1_SPE;
}
阅读全文