2020-03-31 06:34 AM
i dont know how to send variable size data evrytime.
The HMC Mode protocol for the serial port is designed for a 4 wire interface with a fixed protocol featuring
a. 1 Read/Write bit
b. 6 Address bits
c. 24 data bits
please need yout help on how to send >16 bit data packet that include in above format
2020-03-31 08:09 AM
Put the bytes you want to send into an array. Use that array in the argument to HAL_UART_Transmit.
Pretty sure the STM32F4 is limited to an integer number of bytes, so sending 31 bits might be an issue.
2020-03-31 08:14 AM
@TDK actually i want to send data through SPI and not through UART. im trying using int array.. but for addressing 10 different salve register with different data i need 10 different array. right?
2020-03-31 08:18 AM
I meant HAL_SPI_Transmit. The concept is the same. I would suggest arrays of uint8_t rather than int. It takes some amount of programming knowledge to be able to pack the array with the info you want to send.
2020-03-31 08:23 AM
@TDK currently i dont have that kind of programming experience of such type of SPI communicaton.. for that purpose i need the help ...
if you code help me out with hmc767 would be great help.
2020-03-31 01:41 PM
I took a quick look into the user guide ( https://www.analog.com/media/en/technical-documentation/user-guides/140-00074-00_operating_guide.pdf )
and it looks like the reads and writes are 32-bit. The last bit of command is just "don't care". And when reading, the bits after the address bits are "don't care" as well.
The 3 last bits returned while sending the read address byte just are the first bits of data. The previous ones are lock detect signal.
2020-04-01 01:17 AM
@turboscrew i know the size of the data is 32 bit where 1 bit r/w 6 bit address 24 bit data and last bit dont care. but how to send data in SPI i dont know.. i mean if u could provide me with some info. i just want to write the data.. currently not focusing on read operation. can u help with example where u send address + data on same clock in SPI.
2020-04-01 11:03 AM
You can send the messages as bytes or words. You just need to take care of two things:
uint8_t msg[4];
msg[0] = 0x89;
msg[0] = 0xab;
msg[0] = 0xcd;
msg[0] = 0xef;
set_nss();
(void)HAL_SPI_Transmit(&hspi2, msg, 4, 3); // 4 is transfer count, 3 is timeout
unset_nss();
if your SPI (SPI2) is configured for 8-bit transfers.
You can also use:
HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
or
uint8_t msg[8];
msg[0] = 0x89;
msg[0] = 0xab;
msg[0] = 0xcd;
msg[0] = 0xef;
set_nss();
(void)HAL_SPI_Transmit(&hspi2, msg, 4, 3); // 4 is transfer count, 3 is timeout
(void)HAL_SPI_Receive(&hspi2, &msg[4], 4, 3;
unset_nss();
to first send 32-bits and then receive 32-bit response.
SPI doesn't care about delays (unless the speed is too much for the gates), but just the clock pulses and NSS. There could be a week between pulses.
In your case, when you need to receive some response bits during sending the "don't care" address bits, the TransmitReceive is probably the best way.
Make a buffers long enough for both sending and receiving, because the SPI basically exchanges bits - for each received bit there has to be a sent bit and vice versa. Usually zeros are send for receiving. Sometimes drivers cover that by either dropping unused received data during sending, or sending zeroes to receive.