cancel
Showing results for 
Search instead for 
Did you mean: 

hello, im using stm32f446re nucleo board for practice and i have configure the board for SPI communication. i did the program for the 8bit and 16bit DFF. Now i using HMC767 PLL as a salve device whos register size is different from that of nucleo board.

Sbhen.1488
Associate II

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 format0693W000000V52JQAS.png

7 REPLIES 7
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".
Sbhen.1488
Associate II

@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?

TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".
Sbhen.1488
Associate II

@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.

turboscrew
Senior III

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.

Sbhen.1488
Associate II

@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.

You can send the messages as bytes or words. You just need to take care of two things:

  • The byte order
  • The NSS/chip selet/whatchacallit mus not become inactive between the bytes (usually that's true for the whole message).

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.