Getting IIC to work with S912 - 9S12DG256.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getting IIC to work with S912 - 9S12DG256.

3,887 Views
Bastian
Contributor I
Hi,

for days I am trying to get the IIC bus to work on an 9S12DG256. Now, I was hoping you guys could give me some hints what the problem might be.
First of all, I am using the PLL with 24 MHz. Therefore I am using a SCL clock divider of 80 (IBFD = 0x14). Hope that is correct.
I am using the ICC Compiler. This is my code:

Code:
IBFD = 0x14;  // init IBFDIBAD = 0xA0;  // set slave address
IBCR |= 0b10000000;              // IBEN = 1 - IIC bus enableIBCR |= 0b01000000;              // IBIE = 1 - IIC interrupt enable
while(IBSR&0b00100000)
{
 printf("wait until bus is free");
};
printf("bus free");
  
IBCR |= 0b01000000;              // IBIE = 1 - IIC interrupt enable
IBCR |= 0b00010000;              // TX/RX = 1 - transmit mode
IBCR |= 0b00100000;              // MS/SL = 1 - master mode - START signal
printf("START");
IICDR = 0b10010000;              // address slave
printf("slave addressed");

The "START" output is reached but never is the "slave addressed". The controller seems to stop at
IICDR = 0b10010000;
leaving the SDA high (5 V) and the SCL low (0 V).

I have been trying various things but neither seemed to work. Any help would be appreciated.

Regards,
Bastian Goericke

 
 
Added p/n to subject.


Message Edited by NLFSJ on 2008-04-16 03:37 PM
Labels (1)
0 Kudos
11 Replies

1,055 Views
Bastian
Contributor I
Ok, now I found out something interesting.
After one byte is sent and the ISR is called, the 'Acknowledge received' bit in the IBSR is not set. But after the ISR is completed, then, at some point, the 'Acknowledge received' bit is set. I have no idea, why the bit would be set that late.
When I try my other IIC device (which works with my code), the bit is set when the ISR is called (as expected).



Bastian
0 Kudos

1,055 Views
kef
Specialist I
You are enabling IIC interrupts. Do you have IIC interrupt handler somewhere? is IIC vector pointing properly to IIC ISR? If not then it's OK that controller hangs after you write IIC data register.
 
Did you try to use search at the bottom of this page? Also search 8-bit MCU forum. All FSL MCU's have nearly identical IIC peripheral.
0 Kudos

1,055 Views
Bastian
Contributor I
I just tried the code without enabling the interrupt . The controller didn't hang up and reached the "slave addressed".
Seems like something is wrong with the ISR or interrupt vector.
I am using the TwinPEEKs monitor program and I set up the IIC interrupt and ISR like this:

Code:
// I2C Interrupt Handler:    *((unsigned char *)0x3fa3) = 0x06;   // JMP opcode   *((void (**)(void))0x3fa4) = I2Chandler;#pragma interrupt_handler I2Chandlervoid I2Chandler(void){ i2c_flag = 1;}

 As far as I know this should be correct. Do you have any idea why the ISR isn't triggered correctly?

Regards,
Bastian

0 Kudos

1,055 Views
kef
Specialist I
Your ISR handler should acknowledge IIC interrupt by clearing IBIF flag:
 
   IBSR = 2 /*IBSR_IBIF_MASK*/;
 
0 Kudos

1,055 Views
JimDon
Senior Contributor III
There is an app note with a software example that shows a fully interrupt driven master and slave i2c.

The app note is AN2318.pdf, and the software is AN2318SW.zip.
You will have to login to download the software.

You may have to cut and paste the routines into your code, but it is a working example that should answer all your questions.





Message Edited by JimDon on 2008-04-09 10:06 AM
0 Kudos

1,055 Views
Bastian
Contributor I
Thanks Jim, I tried the AN2318 first but I never got the interrupt to work. Probably because I am not using the CodeWarrior but the Imagecraft Compiler. At some point I decided to start from scratch. Now, I am considering to try the AN2318 code again, although there might be more differences between these 2 compilers (e.g. the IBDR is called IICDR in the Imagecraft).

Bastian
0 Kudos

1,054 Views
JimDon
Senior Contributor III
Well, at least the code should serve to show how the registers should be written and how status should be acted upon.

Since CW is free, you could give it a try.

0 Kudos

1,054 Views
Bastian
Contributor I
Yeah, you are right. As a template it should help a lot.

Oh, CW is free? I didn't know that, got the impression it wouldn't be free when I looked at the website.
Maybe I'll will give it a try. But since everyone else in my team is using the ICC, I stuck with that when I first started.

Bastian
0 Kudos

1,054 Views
JimDon
Senior Contributor III
Well, that Standard Edition is free up to 32K.
Also, processor expert will generate code for you for many of the IO's.
And of course CW has the best support as it is from the manufacture.

0 Kudos

1,054 Views
Bastian
Contributor I
Thanks for you help Jim.

I got the IIC bus to run with a modified AN2318 code. Getting to read the temperature from an Maxim DS1624 (thermometer) was astonishing easy. However, I am stuck now with a PCF8583P (real-time clock). It does not respond or acknowledges any data sent to it. I have checked its slave address (1010000x for A0 grounded). Also I have tried various IBFD values (even though I am not exactly sure how to calculate the correct value).
Whatever I try, the themometer always responds correctly, but never does the real-time clock.
Do you have any ideas what the problem might be?

Bastian Goericke
0 Kudos

1,054 Views
Bastian
Contributor I
Thanks kef, that helped. Now the ISR is working although it wasn't easy for me to understand that writing a "1" clears the flag. Especially since the documentation stated: "This bit must be cleared by software, writing a low to it, in the interrupt routine."
Nevertheless, I am finally making some progress. However it may take a while until I reach the functionality described in AppNore2318.


Bastian
0 Kudos