whinger
Joined: 30 Jun 2011 Posts: 2
|
I2C using dsPIC30F2023 |
Posted: Thu Jun 30, 2011 3:47 pm |
|
|
Dear All
I have two I2C issues.
Target - dsPIC30F2023-PI - prototype hardware
MPLAB 8.70
ICD 3 programmer/debugger
PCWHD v4.121
The dsPIC is a I2C master connected to a SAA1064 led driver. The SDA/SCL lines are associated with the I2C on board perpherial, both lines have 2k2 pullups to 5V and are configured as inputs.
A sample of my test code using force_sw is as follows. The code works and illuminates the display
Code: | #FUSES NOBSS,NOWDT,PUT128,ICSP,DEBUG,NOPROTECT,FRC,FRANGE_HIGH,NOOSCIO,NOCKSFSM
#use delay(clock=14.55MHz)
#use I2C(master,scl=PIN_G2,sda=PIN_G3,fast=40000,force_sw)
void vWritetToDisplay(int8 cbyte, int8 digit1, int8 digit2, int8 digit3, int8 digit4)
{
int8 ack;
i2c_start();
ack = i2c_write(0x76); //device address
if (ack){mcTurnOnLED5;}else{mcTurnOffLED5;}
i2c_write(0x00); //instruction byte
i2c_write(cbyte); //control byte
i2c_write(digit1);
i2c_write(digit2);
i2c_write(digit3);
i2c_write(digit4);
i2c_stop();
} |
The FRC oscillator is configured for 14.55MHz, no PLL. I scoped the output pin CLKO and observed 7.27MHz, which is what I expected. The problem I have is that the I2C clk when observed with a scope is 80KHz not the 40KHz i was expecting. Only by changing Code: | #use delay(clock=29.1MHz) |
can I get the I2C clk to be 40KHz. By the way altering the #use delay does not alter the CLKO output (7.27MHz). So the #use delay is not altering the oscillator configuration. Can anyone explain this?
The second issue, seems to be an old chestnut. When I select FORCE_HW, the I2C completely fails. I can observe the start pulse, which is very short (1us). The SCL is not pulled down by the SAA1064. My feeling is the #use delay statement is somehow incorrect and messing up all the I2C hardware timings.
Having spent the last two days trying all sorts of combinations and reading endless posts. I have come to a dead end. I realise the next step is to examine the assembler listings. But before that can anyone spot any glaring errors or oversights on my behalf.
Any help or clarification would be greatly received. Thanks in advance. By the way I am a CCS virgin |
|