[mw_shl_code=c,true]float Read_Results_32Bit_Opcode(unsigned char read_opcode, unsigned char read_addr, unsigned char fractional_bits)
{
unsigned char n_bytes = 3;
unsigned char n;
unsigned int Result_read = 0;
float Result = 0;
unsigned char read_opcode_addr = read_opcode | read_addr;
//.............. Result = n Byte = n x 8 bits......................
// Deactivating Reset SPIx
//GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_RESET);
GPIO_WriteBit(GPIOB, GPIO_Pin_12, Bit_RESET);
SPI_I2S_SendData(SPI2, read_opcode_addr); // READ OPCODE + Address·?????×÷·?
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE)==RESET) {};//????·????ê±?
Simple_delay_43ns((void*)10); // important delay (16) at SPI freq.=750kHz????
//Compulsory reads to DR and SR to clear OVR,
//so that next incoming data is saved
SPI_I2S_ReceiveData(SPI2); // To clear OVR????×?·?
SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE); // To clear OVR?????????ê±?±ê??
//Reading byte1
SPI_I2S_SendData(SPI2, 0x00FF); // DUMMY WRITE·???8??1
// Wait until RX buffer is not empty, then read the received data
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE)==0) {} // ?????????ê±?
Result_read = SPI_I2S_ReceiveData(SPI2); // Read???á??
for (n = 1; n < n_bytes; n++)
{
//Reading byte2 .. byte.n
SPI_I2S_SendData(SPI2, 0x00FF); // DUMMY WRITE·???8??1
// Wait until RX buffer is not empty, then read the received data
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE)==0) {} //?????????ê±?
Result_read = Result_read<<8;
Result_read |= SPI_I2S_ReceiveData(SPI2); // Read
}
//GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET);
GPIO_WriteBit(GPIOB, GPIO_Pin_12, Bit_SET);
Result = Result_read / pow(2, fractional_bits);
return Result;
} [/mw_shl_code]
您看下,就是先写一个类似标志位,然后写地址 返回数据 |