i2c Communication MIMXRT1060

cancel
Showing results for 
Search instead for 
Did you mean: 

i2c Communication MIMXRT1060

234 Views
ArantzaGarcia
Contributor II

Hi!

I am trying to implement a i2c communication between a MIMXRT106 and a PIC16(L)F1934/6/7. The MIMXRT106 is the master and the pic will be the slave. I have tried to send data to the pic but haven´t succeed. 

I don´t know to much about i2c communication and that´s why I would appreaciate some help. Firstly I have used the next function to initalize the i2c communication:

BOARD_LPI2C_Init(BOARD_ACCEL_I2C_BASEADDR, BOARD_ACCEL_I2C_CLOCK_FREQ);

And then I have used the next function to send a message:

BOARD_LPI2C_Send(LPI2C3, SLAVE_ADDRESS, NULL, NULL, 0X12, 1); 

I don´t know if I have defined correctly this last function. I´m pretty sure that the base is correctly defined as I have decided which pins I was going to use. Then I have defined a 7 bit hex number for the slave address and had decided to use NULL for the subaddress and subaddress size, and to finish I have decided that the information I wanted to send is the 0x12 hex number and defined it´s size of 1 byte. I´m not pretty sure if this two final values are correct. 

Thank you,

Arantza. 

Labels (1)
Tags (2)
0 Kudos
7 Replies

208 Views
crist_xu
NXP Employee
NXP Employee

hi. 

    how can you tell that the data send is not success? you read it back? I think that the 0x12 is the device`s reg right?so what is the code seq you used to read the data back? in fact we need to send the reg first.  then restart with read. 

 

   regards,

       crist

0 Kudos

195 Views
ArantzaGarcia
Contributor II

Hi crist_xu,

 

The thing is that when I built the program I receive an error, as if the function isn´t defined as it should, so that´s basically my question, if it looks alright to you or it doesn´t. And the 0x12 is just a random number I have decided. I don´t know what´s the meaning of each number. 

 

Thanks, 

Arantza

0 Kudos

181 Views
crist_xu
NXP Employee
NXP Employee

Hi, 

    about your question, i think that:

  1. you need to define a macro: SDK_I2C_BASED_COMPONENT_USED=1, then the function BOARD_LPI2C_Send(xx) can be used.

   2. the declare of the function: BOARD_LPI2C_Send is : 

status_t BOARD_LPI2C_Send(LPI2C_Type *base, uint8_t deviceAddress,
uint32_t subAddress, uint8_t subaddressSize, uint8_t *txBuff, uint8_t txBuffSize);

   so the 0x12 is not an legal value, you need to define a value, e.g. uint8_t val = 0x12, then pass a pointer value to this funciton, then call the function like this:

   BOARD_LPI2C_Send(LPI2C, SLAVE_ADDR, 0, 0, &val, 1);

 Please have a try.

 

Regards,

   Crist

172 Views
ArantzaGarcia
Contributor II

Hi @crist_xu 

Thank you for your help. Now I have been able to compile the code.

Instead of giving val a value I have defined it like this:

uint8_t val ;
BOARD_Accel_I2C_Send(SLAVE_ADDR, 0, 0, &val);

This function does:

status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff)
{
uint8_t data = (uint8_t)txBuff;

return BOARD_LPI2C_Send(BOARD_ACCEL_I2C_BASEADDR, deviceAddress, subAddress, subaddressSize, &data, 1);

I have debugged and have seen that the value that data guets is 'S' (0x83 I think)

Then it goes to:

reVal = LPI2C_MasterStart(base, deviceAddress, kLPI2C_Write) and reval gets a value of 0x384 which is a value that gets when the code is testing if the bus is busy. 

status_t LPI2C_CheckForBusyBus(LPI2C_Type *base)
{
status_t ret = kStatus_Success;

uint32_t status = LPI2C_MasterGetStatusFlags(base);
if ((0U != (status & (uint32_t)kLPI2C_MasterBusBusyFlag)) && (0U == (status & (uint32_t)kLPI2C_MasterBusyFlag)))
{
ret = kStatus_LPI2C_Busy;
}

return ret;
}

In this function ret gets the value of kStatus_LPI2C_Busy and I don´t understand why. 

Regards,

Arantza. 

0 Kudos

156 Views
crist_xu
NXP Employee
NXP Employee

Hi,

    Have you checked if the slave address is legal? I think that the slave address is a 7bits value, without the read/write bit. so please check if the slave address is right.

    and also please check if the device is working. and check if the pinmux of the i2c you used is configured success and the i2c works well already.

 

Regards,

    Crist

0 Kudos

216 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @ArantzaGarcia 

Talk about my I2C experience at first, normally, when we test the I2C, we can check the I2C wave with the logical analyzer, it will be more easy to check the issues, I mean the I2C bus wave, you can see, when master send data, whether the slave ACK it or not? If not, you need to check your slave datasheet, what's the frequency it needed, not exceed it's mas frequency, then the Slave address is correct or not in the bus, you can compare it with your slave datasheet wave.

  So, please check the I2C bus to do more checking, it will helps your understanding.

  If you meet any issues when you learn it, just kindly let me know.

Best Regards,

Kerry

0 Kudos

193 Views
ArantzaGarcia
Contributor II

Hi @kerryzhou 

The thing is that as I told @crist_xu I can´t even compile. Anywais thank you for the advice and I will put it into practice.

Thank you,

Arantza.

0 Kudos