![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Rob_08
Joined: 27 Nov 2008 Posts: 3
|
I2C problems (with AD7747) |
Posted: Thu Nov 27, 2008 5:19 am |
|
|
Hiya, I'm having problems with basic I2C communication using the built in functions. If I put the function "i2c_isr_state();" anywhere then I get an error saying Undefined identifier "i2c_isr_state".
The code below should simply reset the device and print to the serial port as it does so, however what happens is I get to hello world b and then nothing. Can anyone see what I'm doing wrong and do the built in functions work ?
Code: |
#include <18F452.H>
#fuses NOWDT, NOPROTECT, NOLVP, NOBROWNOUT , H4
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, PARITY=N, BITS=8)
#use i2c(MASTER,SCL=PIN_C3,SDA=PIN_C4,FORCE_HW)
void main (void)
{
printf("\n\n\n\n\n\n\n\n\n\r------ HELLO WORLD a------");
i2c_start();
printf("\n\n\n\n\n\n\n\n\n\r------ HELLO WORLD b------");
i2c_write(0x90); // AD7747 call
i2c_write(0xBF); //Reset AD7747
i2c_stop();
printf("\n\n\n\n\n\n\n\n\n\r------ HELLO WORLD c------");
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Thu Nov 27, 2008 5:34 am |
|
|
I2C_ISR_STATE, is for use inside an ISR. Normally only in a slave device. However your error message, suggests you have an older compiler than the manual you have. There is a equivalent version for older compilers without the function, if you need it (a search here on the forum should find it), but you shouldn't.
The I2C functions on most of the older compilers do work OK.
Obvious question. Have you got the two pullup resistors on the I2C lines? Not having these will cause a hangup.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Rob_08
Joined: 27 Nov 2008 Posts: 3
|
|
Posted: Thu Nov 27, 2008 5:42 am |
|
|
Thank you for the quick response, the manual and the compiler both came off the same disc but I have a feeling it might not be the most up to date version.
I've tried pull up resistors of 10k, 4k7 and 2k2 and nothing seems to change regardless of values.
When you say work on most of the old compilers is there any known bugs with earlier versions? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Thu Nov 27, 2008 6:04 am |
|
|
Only very old versions for this.
Check your version number (top line of the .lst file).
Try something very simple:
Code: |
#include <18F452.H>
#fuses NOWDT, NOPROTECT, NOLVP, NOBROWNOUT , H4
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, PARITY=N, BITS=8)
void main (void) {
int8 dummy;
dummy=input(PIN_C3);
dummy=input(PIN_C4); Make sure both lines are inputs
delay_us(2); //Wait a moment.
dummy=input(PIN_C3)*2 + input(PIN_C4);
printf("\n\n\n\n\n\n\n\n\n\rInput was %d\n", dummy);
while (TRUE); //Always have this at the end of our program
}
|
Unless you see 'Input was 3', there is a wiring error to your I2C lines.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Rob_08
Joined: 27 Nov 2008 Posts: 3
|
|
Posted: Thu Nov 27, 2008 7:02 am |
|
|
Ttelmah, you are amazing !
Been trying to sort this out for quite a while now, and to me my setup was simple generic pic test board --> AD7747 and some pull ups could follow it through and it was fine so it must be software.
However your comments seemed adament the hardware was a problem so time for real picky perfection in the hardware, the test board very kindly includes an LED on all I/O pins including my I2C bus, ripped them off and i can now see my signals being sent over the bus using a scope. Now I just need to sort out numbers
Thank you very very much. Your a star. ![Very Happy](images/smiles/icon_biggrin.gif) |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Thu Nov 27, 2008 9:59 am |
|
|
I call this process, "wall, head, impact technology testing"....
Everybody here who is an 'old hand', has been through it thousands of times. Hence the mantra of stepping 'away', simplifying what you are looking at, and testing what the chip really _is_ seeing.
Got the 'T' shirt.
Glad you have stepped 'forwards'.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|