void LD_WriteReg(LD3320_hw_t * hw,uint8 data1,uint8 data2)//LD3320写寄存器
{
uint8 cmdwrite = 0x04;
LD3320_hw_SetNSS(hw,0);
LD3320_hw_SetSPIS(hw,0);
HAL_SPI_Transmit(hw->spi, &cmdwrite, 1, 1000);
while (HAL_SPI_GetState(hw->spi) != HAL_SPI_STATE_READY);
HAL_SPI_Transmit(hw->spi, &data1, 1, 1000);
while (HAL_SPI_GetState(hw->spi) != HAL_SPI_STATE_READY);
HAL_SPI_Transmit(hw->spi, &data2, 1, 1000);
while (HAL_SPI_GetState(hw->spi) != HAL_SPI_STATE_READY);
LD3320_hw_SetNSS(hw,1);
}
uint8 LD_ReadReg(LD3320_hw_t * hw,uint8 reg_add)//LD3320读寄存器
{
uint8_t txByte = 0x11;//这个txByte随便一个数即可
uint8_t rxByte = 0x00;
uint8 cmdread=0x05;
LD3320_hw_SetNSS(hw,0);
LD3320_hw_SetSPIS(hw,0);
HAL_SPI_Transmit(hw->spi, &cmdread, 1, 1000);
while (HAL_SPI_GetState(hw->spi) != HAL_SPI_STATE_READY);
HAL_SPI_Transmit(hw->spi, ®_add, 1, 1000);
while (HAL_SPI_GetState(hw->spi) != HAL_SPI_STATE_READY);
HAL_SPI_TransmitReceive(hw->spi, &txByte, &rxByte, 1, 1000);
while (HAL_SPI_GetState(hw->spi) != HAL_SPI_STATE_READY);
LD3320_hw_SetNSS(hw,1);
return rxByte;
}
|