Hi NXP Tech Community,
Our customer has configured the S32K148 LPSPI PCS3 to communicate with the ST accelerometer and gyroscope, ASM330LHH. They are testing this on their prototype board.
The S32K148 MCU is reading 2 bytes, where the first byte and second byte data are 0xFF and 0x6B respectively. The first byte 0xFF is an additional byte which the data is not expected by the customer.
Customer would like to know with an example, what is the correct way of reading and writing single and multiple bytes?
Below is the snapshot of project configuration of the customer’s project.
SPI configuration
They are using Chip Select 3.
The transmit and receive buffer size are 10.
When the code is uploaded onto the MCU, it is reading 2 bytes, where the first byte and second byte data are 0xFF and 0x6B respectively. The first byte 0xFF is an additional byte which the data is not expected by the customer.
The oscilloscope is also seeing 0xFF 0x6B. The ST accelerometer and gyroscope address is 0x6B. but the first byte is not expected by the customer.
The customer’s code snippet is as below:
acl_spi2_tx_buf[0] = 0x0FU | 0x80U;//Reading: who iam //acl_spi2_tx_buf[0] = 0x0FU; //| 0x01U;//Reading: who iam //LPSPI_DRV_MasterTransferBlocking(SPI_2,acl_spi2_tx_buf,acl_spi2_rx_buf,5,OSIF_WAIT_FOREVER);
LPSPI_DRV_MasterTransferBlocking(ACL_Slave_Inst,acl_spi2_tx_buf,acl_spi2_rx_buf,2,OSIF_WAIT_FOREVER); |
Solved! Go to Solution.
Hi,
seems the reading is correct, first 0xFF is just dummy byte SPI reads as line is held high.
Reading slave registers consist of sending 2 bytes from master, address and dummy.
And so SPI is reading also 2 bytes, dummy byte (0xFF) and and register value (0x6B).
BR, Petr
Hi,
seems the reading is correct, first 0xFF is just dummy byte SPI reads as line is held high.
Reading slave registers consist of sending 2 bytes from master, address and dummy.
And so SPI is reading also 2 bytes, dummy byte (0xFF) and and register value (0x6B).
BR, Petr
@PetrS @joshua_hong can you tell me what we be a transmitting and receving frame, and how to read this frames. i mean should i send data to slave or just i read data from slave.
you can send data/command to slave first and expect slave to reply data in the same frame. refer to Petr's attached snapshot.
@PetrS @joshua_hong if you have sample code of this communication plz send me. so that i can understand what address and data will be transmit for getting proper reading of IMU data.