Author Topic: PIC24F04 as I2C slave - Address issue  (Read 7057 times)

0 Members and 1 Guest are viewing this topic.

Offline FlanbixTopic starter

  • Contributor
  • Posts: 30
  • Country: gb
  • If you don't know, ask. If you know, share.
PIC24F04 as I2C slave - Address issue
« on: October 20, 2014, 09:08:44 am »
Hi,

I have a PIC24F04KA200 that I use as a I2C slave to drive a strip of WS2812.
I have the program running on the slave working as expect, except that it doesn't matter which address I send first to the I2C, the slave will always process it. For example, my master send 0x1F or 0x00 as the address while the slave is set for 0x1E and it still works.

I thought there was some hardware address matching inside the PIC though (Figure 3 on AN734) which check the incoming address with the register SSPADD (In my case I2C1ADD).

I2C configuration of the slave (MPLABX XC16)
Code: [Select]
    CloseI2C1();
    OpenI2C1((I2C_ON | I2C_7BIT_ADD | I2C_CLK_REL | I2C_STR_EN | I2C_IPMI_DIS), 0);  //Configure I2C1
    ConfigIntI2C1( SI2C_INT_ON | SI2C_INT_ON );
    I2C1ADD = 0x1E;             //I2C address set to 0x1E
    I2C1MSK = 0x00;

Not really an issue for now but I would like to understand why...
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: PIC24F04 as I2C slave - Address issue
« Reply #1 on: October 20, 2014, 10:30:30 am »
Yes, it is done via the IPMI bit and MSK register - under your set-up, it should not respond to any address other than that of your slave address.

You may step throug hthe code and track the right registers to see if plib has set them up correctly or there is an errata for your device.
================================
https://dannyelectronics.wordpress.com/
 

Offline FlanbixTopic starter

  • Contributor
  • Posts: 30
  • Country: gb
  • If you don't know, ask. If you know, share.
Re: PIC24F04 as I2C slave - Address issue
« Reply #2 on: October 20, 2014, 12:22:15 pm »
I tried with I2C1CONbits.IPMIEN set to 0 or 1 but still have the same behavior.
I will probably switch to the PIC24F08KL200 as I need more memory and also have the capacity to debug (This PIC24F cannot be debug without a special header from Microchip).
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: PIC24F04 as I2C slave - Address issue
« Reply #3 on: October 20, 2014, 09:53:07 pm »
You could still debug via uart, pins, or LCD.

the issue could be plib or hardware.
================================
https://dannyelectronics.wordpress.com/
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Re: PIC24F04 as I2C slave - Address issue
« Reply #4 on: October 21, 2014, 08:23:18 am »
You really need to debug the slave Pickit 3 ? , to confirm you are setting the 10 bit slave address in I2C1ADD etc, address 0x00 is also a general call address , 0x1F could be a read for your 0x1E address, how is I2C master using the 7 bits of address, some code shifts address  < 1 and or's the read / write bit, I have worked on PIC24F32KA302  I2C slave code but not used a library , search of forums suggest its not straight forward.   
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4228
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: PIC24F04 as I2C slave - Address issue
« Reply #5 on: October 21, 2014, 08:48:26 am »
The only real problem I've had using I2C on a PIC is speed of response. If the master doesn't support clock stretching - and a good few implementations don't - then you don't have a lot of time between receiving the device or register address, and having to make the first data bit available.

This is the one and only time I've ever had an issue with the free Microchip compiler (XC8) in terms of code performance. The I2C handler only ran fast enough with full optimisation for speed turned on.

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3240
  • Country: gb
Re: PIC24F04 as I2C slave - Address issue
« Reply #6 on: October 21, 2014, 12:04:56 pm »
Are you correctly checking the values in the I2C1STAT register within your interrupt handler? e.g. are you testing the bus collision bit to ensure this hasn't caused an interrupt?
 

Offline FlanbixTopic starter

  • Contributor
  • Posts: 30
  • Country: gb
  • If you don't know, ask. If you know, share.
Re: PIC24F04 as I2C slave - Address issue
« Reply #7 on: October 21, 2014, 01:27:03 pm »
I think the problem may be from the library.
I tried to set the register manually to match what my OpenI2C1 function was supposed to do (Especially the IPMI register bit):
Code: [Select]
   
    //I2C
    CloseI2C1();
    OpenI2C1((I2C_ON | I2C_7BIT_ADD | I2C_CLK_REL | I2C_STR_EN | I2C_IPMI_DIS), 0);  //Configure I2C1
    ConfigIntI2C1( SI2C_INT_ON | SI2C_INT_ON );
    I2C1ADD = 0x1F;             //I2C address set to 0x1F
    I2C1MSK = 0x00;
    I2C1CONbits.IPMIEN = 0;
    I2C1CONbits.GCEN = 0;
    I2C1CONbits.A10M = 0;


Now I can see a NACK instead of a ACK after the address is sent when I set the slave address to 0x18 . And it is sending a ACK only when the address of the slave is 0x1F.
I know that the library functions are not the be trusted but still, I am surprise to have this kind of error.

Thanks for the help.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: PIC24F04 as I2C slave - Address issue
« Reply #8 on: October 22, 2014, 01:16:28 am »
I guess it is the first mover's disadvantage: their hardware is too disparate that writing high quality / consistent software to cover all devices is tough.

================================
https://dannyelectronics.wordpress.com/
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4228
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: PIC24F04 as I2C slave - Address issue
« Reply #9 on: October 22, 2014, 09:32:14 am »
I'm not at all surprised, and it's one reason I just don't use manufacturers' libraries for simple, low level functions like this.

Reading the data sheet (including the errata, *especially* for PICs) and setting register values yourself is the only way to really know how the hardware is configured, and therefore, how it will behave.

Use a library, and you still need to know how the hardware is configured, but you also need to know how to make the library actually set up that configuration.

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: PIC24F04 as I2C slave - Address issue
« Reply #10 on: October 22, 2014, 10:31:55 am »
The source code seems to set up the bits correctly. The issue here might be a "OR" style config word or "AND" style config word.
================================
https://dannyelectronics.wordpress.com/
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf