PIC32. Problems with I2C.
Posted: Sun Jan 24, 2010 7:37 pm
My hard- and software: PIC32MX360F512L 80MHz, matlab 2008a.
Hi Lubin,
I'm trying to communicate with a HMC5843 sensor. It's a I2C device. For this task I have built a very simple model. I want to use I2C 1 with 400 kHz. The reload value for the BRG can be calculated or taken from the table according the PIC32MX Family Reference Manual, Section 24(DS61116D) p.32. I take the I2CxBRG value for 40 MHz PBCLK from the table 24-1. It is 0x030 or 48 in decimal. I put then this value into the I2C Master Block and get Fscl = 661.157 kHz. Why? Shouldn't be a value about 400 kHz? It's my first problem. The next problem occurs if I try to compilate the model. I get an error message like:
Error using ==> genMakefileAndBuild at 1138
and in Command Window
magnet_field_sensor.c: In function `magnet_field_sensor_step':
magnet_field_sensor.c:48: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:55: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:58: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:67: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:70: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:79: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:82: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:91: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:94: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:104: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:111: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:114: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:124: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:127: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:134: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:137: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:148: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:151: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:170: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:173: error: union has no member named `MI2C1IF'
gmake: *** [magnet_field_sensor.o] Error 1
Could you please give me an advise what I'm doing wrong?
Regards
Oliver
Hi Lubin,
I'm trying to communicate with a HMC5843 sensor. It's a I2C device. For this task I have built a very simple model. I want to use I2C 1 with 400 kHz. The reload value for the BRG can be calculated or taken from the table according the PIC32MX Family Reference Manual, Section 24(DS61116D) p.32. I take the I2CxBRG value for 40 MHz PBCLK from the table 24-1. It is 0x030 or 48 in decimal. I put then this value into the I2C Master Block and get Fscl = 661.157 kHz. Why? Shouldn't be a value about 400 kHz? It's my first problem. The next problem occurs if I try to compilate the model. I get an error message like:
Error using ==> genMakefileAndBuild at 1138
and in Command Window
magnet_field_sensor.c: In function `magnet_field_sensor_step':
magnet_field_sensor.c:48: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:55: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:58: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:67: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:70: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:79: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:82: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:91: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:94: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:104: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:111: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:114: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:124: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:127: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:134: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:137: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:148: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:151: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:170: error: union has no member named `MI2C1IF'
magnet_field_sensor.c:173: error: union has no member named `MI2C1IF'
gmake: *** [magnet_field_sensor.o] Error 1
Could you please give me an advise what I'm doing wrong?
Regards
Oliver