Hi everyone,
I just entered this platform and have a little question.
Using S32DS 3.6.1 , RTD S32K3_RTD_4_0_0_D2311_ASR_REL_4_7_REV_0000_20231128 and S32K312 MCU.
I want to use the lpi2c interface as master.
and want to transmit data to slave with addr 0xa5.
when i using the function :
Lpi2c_Ip_StatusType Lpi2c_Ip_MasterSendData(uint8 Instance,
uint8 * TxBuff,
uint32 TxSize,
boolean SendStop)
where should i set the slave addr 0xa5?
in the parameter Txbuff?
Or should i using other functions? if so which function should i use?
Solved! Go to Solution.
Hi@willy2
yes, use "Lpi2c_Ip_MasterSetSlaveAddr()"to change slave address.
I'm using the LPI2C0 as master and need to communicate with multi slave device.
assume 2 device with addr 0x10 & 0x20.
I see that when i do Lpi2c_Ip_MasterInit ,it will set slave address as 0x10.
if i want to trnsmit to other slave device ,what do i do it?
reset slave address with function Lpi2c_Ip_MasterSetSlaveAddr?
Hi@willy2
yes, use "Lpi2c_Ip_MasterSetSlaveAddr()"to change slave address.
Hi Senlent,
thanks to reply.
one more question.
where should i set the interrupt callback functions?
i want to do a "read" to slave.
so it means i have to do a transmit to slave and then do receive frome slave ,right?
according to above , i write a callback function for transmit interrupt to receive from slave.
where should i put this callback?
Hi@willy2
I don't understand your question.
Usually, the LPI2C callback function is unnecessary.
Users can use a timer to send and receive messages regularly.
You can see the description below:
Hi @Senlent ,
my i2c usage is ported from other platform.
we use transmit_end_callback to do receive function if necessary.
For example :
i want to read from addr 0x10 's register 0x12
first we do i2c_master_transmit_withoutstop(0x10,0x12);
and the transmit_end_callback(note it is a irq) to do i2c_master_receive();
i would like to do if i can unchange it.
"Users can use a timer to send and receive messages regularly."
--->what does this do? can u do a simple psudo code to let me see ?
again ,thanks to repling
Hi@willy2
You have overcomplicated the problem.
The I2C driver provided by RTD only provides two sending and receiving methods, namely blocking and no-blocking.
You can enable the I2C interrupt, but this interrupt handler is usually only used to check the status of the transmission, as shown in my previous screenshot.
1. For the blocking sending mode, you can call Lpi2c_Ip_MasterReceiveDataBlocking() immediately after calling Lpi2c_Ip_MasterSendDataBlocking();
2. For the no-blocking sending mode: that is: Lpi2c_Ip_MasterReceiveDataBlocking(), after calling this function, you need to call "Lpi2c_Ip_MasterGetTransferStatus()" to ensure that the transmission is successful, and then call "Lpi2c_Ip_MasterReceiveData()" in the same way.
Hi @Senlent ,
ok maybe i do complicated it.
it leads me some question.
1. what's the different of blocking & no-bolcking?
2. you mention the method of no-blocking sending mode ,i dont see the transfer here , is there somewhere wrong in here? Or maybe I understood it wrongly?
3. you say that
""Lpi2c_Ip_MasterReceiveDataBlocking(), after calling this function, you need to call "Lpi2c_Ip_MasterGetTransferStatus()" to ensure that the transmission is successful""
I look up the Lpi2c_Ip_MasterReceiveDataBlocking() , and it have do Lpi2c_Ip_MasterGetTransferStatus() already, does it means i need to call this function again? or just let me understand the flow?
1. what's the different of blocking & no-bolcking?
Blocking Send
After the function is called, the CPU will wait for the data transfer to complete before continuing to execute the subsequent code.
Non-blocking Send
The function returns immediately after the call, and the data transfer is performed in the background, usually through interrupts or DMA.
2.&3.
My mistake, copy error:
"
2. For the no-blocking sending mode: that is: Lpi2c_Ip_MasterReceiveDataBlocking(), after calling this function, you need to call "Lpi2c_Ip_MasterGetTransferStatus()" to ensure that the transmission is successful, and then call "Lpi2c_Ip_MasterReceiveData()" in the same way.
"
change to:
"
For the no-blocking sending mode: that is: Lpi2c_Ip_MasterSendData(), after calling this function, you need to call "Lpi2c_Ip_MasterGetTransferStatus()" to ensure that the transmission is successful, and then call "Lpi2c_Ip_MasterReceiveData()" in the same way.
"
For no-blocking sending and receiving, you must call Lpi2c_Ip_MasterGetTransferStatus() every time.
.