Getting Start with MX RT1170 EVK and I2C

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getting Start with MX RT1170 EVK and I2C

Jump to solution
2,784 Views
allmo
Contributor II

Hello everyone,

I want to use the MX RT1170 evalboard as a rapid control prototyping system together with Matlab and Simulink and the model based design toolbox. My first step is to integrate an I2C sensor into the system and read sensor values into simulink. I want to connect the sensor to the provided arduino interface (analog in, pin 4 &5).

I took a short at the examples in the model based design toolbox, but either the docu is missing or it is the wrong one for the example.

I am not sure wether i need to use the block LPI2C or the FlexIO I2C blocks.

Are there any schematics where I can see which pins of the cpu belong to the arduino?

0 Kudos
1 Solution
2,769 Views
nxa11767
NXP Employee
NXP Employee

Hello @allmo ,

You can get the schematics of the board from the nxp site: 

https://www.nxp.com/design/development-boards/i-mx-evaluation-and-development-boards/i-mx-rt1170-eva... under Design Resources -> Printed Circuit Boards and Schematics  

You can use LPI2C peripheral and look into the examples what pins are being used. 

As for the toolbox examples on LPI2C, you need to browse to the example directory to see the right help/readme file: e.g if you open the evkmimxrt1170_lpi2c_master_trans_recv.mdl and want to see its readme, type in the command window:

[ex_path, ~] = fileparts(which('evkmimxrt1170_lpi2c_master_trans_recv')); cd(ex_path);

in Readme.html you can find the SDA and SCL pins mapping and in the file with .mex extension (MCUX Configuration File) you can find exactly the settings done for LPI2C. To open the .mex file from simulink, open a NXP simulink block (e.g LPI2C Read) and press the Configure button. This will open the .mex file with MCUX Configuration Tool, you can make changes there and just save the file before returning back to Simulink. In Simulink press the Update button for the changes done in the .mex file to be read back in Simulink,

Best regards,

Alexandra

View solution in original post

0 Kudos
9 Replies
2,758 Views
allmo
Contributor II

Hello @nxa11767 

thank you for information. 

Especially the schematics helped me a lot to understand how to interact with the arduino interface.

Additionally I found all the documentations for the examples!

 

For a first test i created the following model to receive the data from the i2c sensor over the external mode:

allmo_0-1623841088221.png

 

The code generation (Monitor&Tune) is working, but when i connect to the board and press the start button i cannot see anything in the scope. Do I make any mistakes?

Why has the block output Data Rx the size unit8, although i request a size of 2 bytes?

Best regards,

Moritz

 

0 Kudos
2,753 Views
nxa11767
NXP Employee
NXP Employee

Hi @allmo ,

The size of Data Rx is an array of uint8 elements, so you'll need to define the size of your data storage variable that will be used to store the Data Rx:

nxa11767_1-1623847185541.png

 

As for external mode, have you set the correct COM port in the Model Hardware Settings?

nxa11767_0-1623847028125.png

Do you get any errors in the Diagnostics view?

Best regards,

Alexandra

 

0 Kudos
2,748 Views
allmo
Contributor II

Hello @nxa11767 

i changed the block parameters in the data store memory.

I have checked the com port too. It is the same one as in the device manager of windows.

As stop time of the model i choosed "inf", I hope that's right.

When i try to connect with the board after i pressed the restart button, I got the following error message (see file error_simulink.txt)

Best regards,

Moritz

 
 
Tags (1)
0 Kudos
2,730 Views
nxa11767
NXP Employee
NXP Employee

Hi @allmo ,

 

Try decreasing the  Duration  in Signal&Trigger options, in External Mode Control Panel:

nxa11767_1-1623912007782.png

 

nxa11767_0-1623911912946.png

The toolbox provides also an example for external mode (evkmimxrt1170_extmode.slx), you can try to run that one also.

Best regards,

Alexandra

 

0 Kudos
2,721 Views
allmo
Contributor II

Hello @nxa11767 

i have decreased the duration setting in the signal and trigger options, but i got a new error message

Error_Simulink.png

As i proposed i testet the external mode example of the toolbox. After I had set the correct settings, the example ran.

Then I inserted the i2c-blocks to the exampel model to test, whether the error depend on the model setting. After I have compiled the model with the inserted blocks, i unfortunaly  got the same errros.

 

Bes regards,

Moritz

0 Kudos
2,665 Views
stefancinipeanu
NXP Employee
NXP Employee

Hello @allmo 

I have a few suggestions for external mode working.

If your Simulink model is saved as .mdl, try to save it as .slx and then run external mode again.

Also, I recommend to set a specific fixed step-size in the solver configuration for your model.

config_params.JPG

Make sure that the COM port associated with your board is not open or used by another process. Otherwise, your board cannot send data to Simulink.

Also, make sure that the sensor you are using is sending data to your board. The communication between Simulink and the board might be cut off because the board might be stuck in an I2C call function waiting for the data from the slave device.

If your are trying just to visualize the data your are receiving, you can use FreeMaster tool which is supported by our toolbox. The FreeMaster blocks can be found in the Utility Blocks from NXP Model-Based Design Toolbox for i.MX RT MCUs in Simulink Library Browser. 

Best regards,

Stefan

0 Kudos
2,642 Views
allmo
Contributor II

Hello @stefancinipeanu ,

thank you for your advice, I will implement your suggestions!

Yesterday morning I copied the exampel for GPIO-Polling, saved it as .slx-fiel and inserted the I2C-block. I configured the model for the external, downloaded it and it it worked the first time. As thought about changes between the first test model and this model, I detected that i remove all necessary pins in the mcuxpresso settings, except for uart and lpi2c pins.

Could this have caused the problems?

 

Best regards,

Moritz

0 Kudos
2,636 Views
stefancinipeanu
NXP Employee
NXP Employee

Hi @allmo 

The removal of the pins for peripherals that you are not using in your application should not influence the external mode working.

Another suggestion is to set the LPIC2 peripheral in a non-blocking mode, like Transfer or Interrupts. You can do that by opening the MCUXpresso ConfigTools file associated with your model, save the file, click the Update button in the LPI2C block and go back to Simulink to try again. This way you will prevent the board to wait for the data from the slave device.

Best regards,

Stefan

0 Kudos
2,770 Views
nxa11767
NXP Employee
NXP Employee

Hello @allmo ,

You can get the schematics of the board from the nxp site: 

https://www.nxp.com/design/development-boards/i-mx-evaluation-and-development-boards/i-mx-rt1170-eva... under Design Resources -> Printed Circuit Boards and Schematics  

You can use LPI2C peripheral and look into the examples what pins are being used. 

As for the toolbox examples on LPI2C, you need to browse to the example directory to see the right help/readme file: e.g if you open the evkmimxrt1170_lpi2c_master_trans_recv.mdl and want to see its readme, type in the command window:

[ex_path, ~] = fileparts(which('evkmimxrt1170_lpi2c_master_trans_recv')); cd(ex_path);

in Readme.html you can find the SDA and SCL pins mapping and in the file with .mex extension (MCUX Configuration File) you can find exactly the settings done for LPI2C. To open the .mex file from simulink, open a NXP simulink block (e.g LPI2C Read) and press the Configure button. This will open the .mex file with MCUX Configuration Tool, you can make changes there and just save the file before returning back to Simulink. In Simulink press the Update button for the changes done in the .mex file to be read back in Simulink,

Best regards,

Alexandra

0 Kudos