I2C not working on dsPic33EP512GM304

Post Reply
Author
Message
MikeCLX
Posts: 14
Joined: 30 Jan 2014 06:22

I2C not working on dsPic33EP512GM304

#1 Post by MikeCLX » 14 Jun 2020 00:38

I have been scratching my head for days and not getting anywhere with a I2C problem on the dsPic33EP512GM304

I am using MB but i dont think thats related as this seems to be a chip issue

My issue is I2C wont do anything! im getting nothing on the Logic analyzer.

My Setup:
using ASDA1 and ASCL1 pins to talk to a 24SC01 EEProm
Have 2.2K pullups on both lines
Have Setup Fuse set for A pins
Set all pins as Digital
Set both pins (B8 and A9) as inputs
Int the I2C1

As you can see in the code i have tried all sorts of other config bits that normally i have never needed to set to try and resolve the issue to no avail

Interesting Observations and tests:
  1. It works from a easypic Fusion V7 board jumpering the 2 pins to my board and disable i2C on my dsPic, this confirms the circuit on my board is good, i tried 3 different I2C ports from this easypic board all worked great
    the Fusion board had a dsPIC33EP512MU810 Processor, its running essentially the same code bar the odd chip difference.
  2. The SCL line on my board reads low when i Init the I2C??? the pin is high on the scope and Logic analyzer, but if i read PortB.8 it is 0 PortA.9 is 1 ?? this is confusing as i dont see why it should read low when the pin is high.
  3. If i use the Built in I2C Read then it hangs, im using some non hanging code in this forum to stop it hanging, but both work fine in test #1
  4. SPI and any other function i have tested so far works on this chip


This is the latest code for the EEprom

Code: Select all

Sub Procedure SetupEE(Dim Node as byte)
    LatA.9 = 1
    LatB.8 = 1
    TRISA.9 = 1
    TRISB.8 = 1
    Delay_100ms()
    CVR1CON.6=0 'Ensure Voltage Ref is disconnected from pin
    pmd1.7=0 'enable I2C1 module
    I2C1Con.9=1  'DISABle Slew rate control
    I2C1Con.8=0  'SMEN SMBus Disable
    I2C1Con.11=0 'Disable IPMIEN
   I2C1_Init(100000)      ' initialize I2C communication
   NodeAddress = node
end sub


sub procedure EEWriteByte(dim DataAddress as byte,Dim Value as byte)
   TRISC.2 = 0                'Set Write Protection to output
   Latc.2 = 0                 '0= can write to EEPROM

  NodeAddress = 160

  I2C1_Start()           ' issue I2C start signal
  I2C1_Write(NodeAddress)       ' send byte via I2C  (device address + W)
  I2C1_Write(DataAddress)          ' send byte (address of EEPROM location)
  I2C1_Write(Value)       ' send data (data to be written)
  I2C1_Stop()            ' issue I2C stop signal
  'Delay_100ms()
end sub


sub Function EEReadByte(dim DataAddress as byte) as byte
  NodeAddress = 160
  I2C1_Start()           ' issue I2C start signal
  I2C1_Write(NodeAddress)       ' send byte via I2C  (device address + W)
  I2C1_Write(DataAddress)          ' send byte (data address)
  I2C1_Restart()         ' issue I2C signal repeated start
  I2C1_Write(NodeAddress+1)       ' send byte (device address + R)
  result =  I2C1_Read(1)   ' Read the data (NO acknowledge)
  I2C1_Stop()            ' issue I2C stop signal
end sub
this is the simpler code that works on the Fusion V7 (neither work on the GM304) I started from here and have added to the setup to try and resolve it on the GM304

Code: Select all

Sub Procedure SetupEE(Dim Node as byte)
   I2C1_Init(100000)      ' initialize I2C communication
   NodeAddress = node
end sub
Any Ideas? i have been pulling my hair out for days on this one and im running out of hair

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: I2C not working on dsPic33EP512GM304

#2 Post by jovana.medakovic » 15 Jun 2020 15:02

Hello,

Please, check if you set configuration bits correctly.
If you want to use Alternate I2C1 Pins (ASCL1 and ASDA1), you need to enable it in the Edit Project windows (Ctrl+Shift+E) -> Alternate I2C1 pins - Enable.

Kind regards,
Jovana

MikeCLX
Posts: 14
Joined: 30 Jan 2014 06:22

Re: I2C not working on dsPic33EP512GM304

#3 Post by MikeCLX » 16 Jun 2020 12:13

Yes i can confirm its setup correctly,

I have logged a call with microchip to see if its a bug in this chip.

Its looking like either that or a bug in mikrobasic not setting the config correctly at this point from the testing and it working on the 810 chip

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: I2C not working on dsPic33EP512GM304

#4 Post by jovana.medakovic » 17 Jun 2020 14:44

Hi,

Can you tell me which development system you are using for dsPic33EP512GM304 MCU?
Can you send me a schematic where I can see your connections?
Also, if you can, zip and send me your project for review?

Kind regards,
Jovana

MikeCLX
Posts: 14
Joined: 30 Jan 2014 06:22

Re: I2C not working on dsPic33EP512GM304

#5 Post by MikeCLX » 30 Jun 2020 21:47

Just for completeness for anyone else searching this...

I have been working through this with microchip and there is an error in the data sheet. they will print an errata on this chip.

The ASCL1 pin is correct on pin 44 (RB8)

but the ASDA1 pin is on pin 1 (RB9) NOT pin 35 (RA9) as shown on the datasheet.

So its rebuild my boards for me...

Post Reply

Return to “dsPIC Compilers General”