Hi friends, is a pleasure to be here. I am working with the protocol I2C using the microcontroller S32K118. I am working with a device calls KTS1622EUAA-TR that is a extenser of inputs and outputs. The good news that I2c fuction of the program lpi2c_master_s32k118 it is working because it reconigzed the device to write and read, but I want to work the registers of the device so the problem that I have here which the fuction that I can write to the registers of the device, the fuctions for it are this:
status_t LPI2C_DRV_MasterSendData(uint32_t instance,
const uint8_t * txBuff,
uint32_t txSize,
bool sendStop)
status_t LPI2C_DRV_MasterSendDataBlocking(uint32_t instance,
const uint8_t * txBuff,
uint32_t txSize,
bool sendStop,
uint32_t timeout)
Another thing that I want to use for this is to read the state of the inputs and outputs of the device
status_t LPI2C_DRV_MasterReceiveData(uint32_t instance,
uint8_t * rxBuff,
uint32_t rxSize,
bool sendStop)
status_t LPI2C_DRV_MasterReceiveDataBlocking(uint32_t instance,
uint8_t * rxBuff,
uint32_t rxSize,
bool sendStop,
uint32_t timeout)
please let me know about it,
ok for example if I want to write in int the register 0x06 to configurate all the pins of the port0 as input or output, how it will be using the function LPI2C_DRV_MasterSendDataBlocking(uint32_t instance, const uint8_t * txBuff, uint32_t txSize, bool sendStop, uint32_t timeout)?
It will something like this, because I am not sure to send the information to the device
/* Definition of the data transfer size */
#define TRANSFER_SIZE (3u)
uint8_t buffer3[TRANSFER_SIZE]={0x05,0xFF};
LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C1,buffer3,TRANSFER_SIZE, true, OSIF_WAIT_FOREVER);
Please let me know friends
Best Regards,
Rony Vargas
Hi @Eletronicc_23,
The address of the device is sent automatically.
In this example, you need TRANSFER_SIZE = 2.
The tx_buffer should contain the address of the register and the data to be written to that register.
Please use a logic analyzer ot an oscilloscope to verify the transfer on the bus.
Regards,
Daniel
Ok good, in this case to receive how will be the example?, I understand if I send the register 0X00, it will send me back the state of the input to see how is the configuration of the Port depending the pin that I want to read. it is something like this:
#define RECEIVE_SIZE (2u)
uint8_t masterTxBuffer[TRANSFER_SIZE]={0x00};
uint8_t masterRxBuffer[TRANSFER_SIZE];
LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C1, masterTxBuffer,RECEIVE_SIZE, true, OSIF_WAIT_FOREVER);
LPI2C_DRV_MasterReceiveDataBlocking(INST_LPI2C1, masterRxBuffer,RECEIVE_SIZE, true, OSIF_WAIT_FOREVER);
The SendDataBlocking should not send the STOP condition in this case.
RECEIVE_SIZE should be 1 if you read just one register, but this depends on the Slave device, please refer to the datasheet of the device.
Regadrs,
Daniel
ok in this case I want to read the input of PORT0 that is the register 0x00, so it will be like this my friend if I am not wrong:
#define RECEIVE_SIZE (1u)
uint8_t masterTxBuffer[ RECEIVE_SIZE]={0x00};
uint8_t masterRxBuffer[ RECEIVE_SIZE];
LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C1, masterTxBuffer,RECEIVE_SIZE, false, OSIF_WAIT_FOREVER);
LPI2C_DRV_MasterReceiveDataBlocking(INST_LPI2C1, masterRxBuffer,RECEIVE_SIZE, true, OSIF_WAIT_FOREVER);
Best Regards
HI @Eletronicc_23,
The KTS1622 datasheet specifies the format.
https://www.kinet-ic.com/uploads/KTS1622-04d.pdf
For example:
If you decide to use the blocking method, it should be something like this:
LPI2C_DRV_MasterSendDataBlocking(uint32_t instance, const uint8_t * txBuff, uint32_t txSize, bool sendStop, uint32_t timeout);
where txSize = 1 and sendStop = 0.
followed by
LPI2C_DRV_MasterReceiveDataBlocking(uint32_t instance, uint8_t * rxBuff, uint32_t rxSize, bool sendStop, uint32_t timeout);
where rxSize = 1 and sendStop = 1.
If you use the non-blocking method, you need to use this function to get the status of the transfer.
LPI2C_DRV_MasterGetTransferStatus(uint32_t instance, uint32_t *bytesRemaining);
Regards,
Daniel
ok for example if I want to write in int the register 0x06 to configurate all the pins of the port0 as input or output, how it will be using the function LPI2C_DRV_MasterSendDataBlocking(uint32_t instance, const uint8_t * txBuff, uint32_t txSize, bool sendStop, uint32_t timeout)?
It will something like this, because I am not sure to send the information to the device
/* Definition of the data transfer size */
#define TRANSFER_SIZE (3u)
uint8_t buffer3[TRANSFER_SIZE]={0x05,0xFF};
LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C1,buffer3,TRANSFER_SIZE, true, OSIF_WAIT_FOREVER);
Please let me know friends
Best Regards,
Rony Vargas