EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

I2C example and winARM LPC2148

Started by nerdinrage May 20, 2009
I was wondering if anyone could point me towards a working i2c example for winarm. I modified the one from the not ported/tested directory, added rprintf to it to send error messages to the comport. I also fixed the pinsel and iodir issues between rprintf and the i2c header. The communication structure of the chip in the example and the chip I am using are the same. I seem to be getting a I2C not started error and an I2C max timeout exit condition.

Does anyone have any tips or tricks? I am using the embedded artist quickstart + dev board. I did notice that the I2C scl at P0.2 is a bit rounded. I have the Duty cycle and pulse width set per the spec sheet ~400 khz 0.6+us and 1.3+us. Checked and double checked slave and register addresses. The test program I compiled had one read cycle to read reset values of a config register and one write cycle to turn on all the 4 digital outs on the chip.

I had an o-scope on my sda line and while the DAQ chip should have been sending data it looked like:

_⌐⌐⌐⌐⌐_ pretty much idle high with an 87% ish duty cycle

An Engineer's Guide to the LPC2100 Series

If you are referring to the IIC driver as part of newlib-lpc (in untested on Robert's site), then I wrote this one and it has been serving me well for a few years now. Of course you will need to go through and change hardware specific things for your lpc processor variant, especially things like IOPIN and PINSEL.

Ensure the IIC external pullup resisters you have on the IIC bus are low enough in value to get good mostly square waveforms on clock and data. The value will vary dependent on the fan-out of IIC devices and the capacitance of the trackwork. You can always increase them again once you get it working. Try setting the IIC clock speed ridiculously low speed (bigger divider), again till you get it working.

If you are using newlib-lpc, note that in the more recent lpc variants, NXP have changed how the VIC interrupt priorities work, and the clocking/PCLK divider chains, so changes will be required in the system code too if you have one of these.

Cheers,
Bruce
-----Original Message-----
From: l... [mailto:l...] On Behalf Of nerdinrage
Sent: Thursday, 21 May 2009 4:53 AM
To: l...
Subject: [lpc2000] I2C example and winARM LPC2148

I was wondering if anyone could point me towards a working i2c example for winarm. I modified the one from the not ported/tested directory, added rprintf to it to send error messages to the comport. I also fixed the pinsel and iodir issues between rprintf and the i2c header. The communication structure of the chip in the example and the chip I am using are the same. I seem to be getting a I2C not started error and an I2C max timeout exit condition.

Does anyone have any tips or tricks? I am using the embedded artist quickstart + dev board. I did notice that the I2C scl at P0.2 is a bit rounded. I have the Duty cycle and pulse width set per the spec sheet ~400 khz 0.6+us and 1.3+us. Checked and double checked slave and register addresses. The test program I compiled had one read cycle to read reset values of a config register and one write cycle to turn on all the 4 digital outs on the chip.

I had an o-scope on my sda line and while the DAQ chip should have been sending data it looked like:

_⌐⌐⌐⌐⌐_ pretty much idle high with an 87% ish duty cycle

The resisters on the board are 3K as per the embedded artist's spec sheet. The bus is already wired to a I2C eprom, so I thought it would work with another device... but you know I never checked to see if they had the same slave address 0x90. This would be an issue if they are both responding to the same name. ... nope eeprom is 0xa0. I guess I did assume that the file was in an lpc2138/48 folder and that the addresses were correct in the header. Anything off the top of your head I should look at first.

I am new to this whole making sure system files are correct. I suppose my professors were overly kind to me when they gave me equipment that "just works". Oh this is a wonderful learning experience.

There is a point for conversation in there... would it be worthwhile to force students to make things work... you know... instead of handing them known good/operational and patting them on the head when the leds go on and off?

I was shocked to find out that standard library functions weren't supported, or um well defined.

Thanks for the notes I'll see what I can dig up. If anyone wants to jump in and offer some advice I would appreciate it. I'm actually taking some time off of work the first week of june to dive head first into this project. The goal of the 23rd I guess was a bit overzealous.

Thanks

--- In l..., "Bruce Paterson" wrote:
>
> If you are referring to the IIC driver as part of newlib-lpc (in untested on Robert's site), then I wrote this one and it has been serving me well for a few years now. Of course you will need to go through and change hardware specific things for your lpc processor variant, especially things like IOPIN and PINSEL.
>
> Ensure the IIC external pullup resisters you have on the IIC bus are low enough in value to get good mostly square waveforms on clock and data. The value will vary dependent on the fan-out of IIC devices and the capacitance of the trackwork. You can always increase them again once you get it working. Try setting the IIC clock speed ridiculously low speed (bigger divider), again till you get it working.
>
> If you are using newlib-lpc, note that in the more recent lpc variants, NXP have changed how the VIC interrupt priorities work, and the clocking/PCLK divider chains, so changes will be required in the system code too if you have one of these.
>
> Cheers,
> Bruce
> -----Original Message-----
> From: l... [mailto:l...] On Behalf Of nerdinrage
> Sent: Thursday, 21 May 2009 4:53 AM
> To: l...
> Subject: [lpc2000] I2C example and winARM LPC2148
>
> I was wondering if anyone could point me towards a working i2c example for winarm. I modified the one from the not ported/tested directory, added rprintf to it to send error messages to the comport. I also fixed the pinsel and iodir issues between rprintf and the i2c header. The communication structure of the chip in the example and the chip I am using are the same. I seem to be getting a I2C not started error and an I2C max timeout exit condition.
>
> Does anyone have any tips or tricks? I am using the embedded artist quickstart + dev board. I did notice that the I2C scl at P0.2 is a bit rounded. I have the Duty cycle and pulse width set per the spec sheet ~400 khz 0.6+us and 1.3+us. Checked and double checked slave and register addresses. The test program I compiled had one read cycle to read reset values of a config register and one write cycle to turn on all the 4 digital outs on the chip.
>
> I had an o-scope on my sda line and while the DAQ chip should have been sending data it looked like:
>
> _⌐⌐⌐⌐⌐_ pretty much idle high with an 87% ish duty cycle
>
>
>
>
>
>
>From memory the newlib-lpc driver accepts the actual IIC address. Check that 0xa0 is in fact this, not twice the address (7 addr bits shifted left to allow for R/W bit). You may need to pass 0x50.

Failing that, get out an oscilloscope and look at the IIC lines. Is the device replying with an ack, or nothing at all ?

If the waveforms look quite rounded, try smaller pullup resisters.

Cheers,
Bruce
-----Original Message-----
From: l... [mailto:l...] On Behalf Of nerdinrage
Sent: Thursday, 21 May 2009 1:57 PM
To: l...
Subject: [lpc2000] Re: I2C example and winARM LPC2148

The resisters on the board are 3K as per the embedded artist's spec sheet. The bus is already wired to a I2C eprom, so I thought it would work with another device... but you know I never checked to see if they had the same slave address 0x90. This would be an issue if they are both responding to the same name. ... nope eeprom is 0xa0. I guess I did assume that the file was in an lpc2138/48 folder and that the addresses were correct in the header. Anything off the top of your head I should look at first.

I am new to this whole making sure system files are correct. I suppose my professors were overly kind to me when they gave me equipment that "just works". Oh this is a wonderful learning experience.

There is a point for conversation in there... would it be worthwhile to force students to make things work... you know... instead of handing them known good/operational and patting them on the head when the leds go on and off?

I was shocked to find out that standard library functions weren't supported, or um well defined.

Thanks for the notes I'll see what I can dig up. If anyone wants to jump in and offer some advice I would appreciate it. I'm actually taking some time off of work the first week of june to dive head first into this project. The goal of the 23rd I guess was a bit overzealous.

Thanks

--- In l..., "Bruce Paterson" wrote:
>
> If you are referring to the IIC driver as part of newlib-lpc (in untested on Robert's site), then I wrote this one and it has been serving me well for a few years now. Of course you will need to go through and change hardware specific things for your lpc processor variant, especially things like IOPIN and PINSEL.
>
> Ensure the IIC external pullup resisters you have on the IIC bus are low enough in value to get good mostly square waveforms on clock and data. The value will vary dependent on the fan-out of IIC devices and the capacitance of the trackwork. You can always increase them again once you get it working. Try setting the IIC clock speed ridiculously low speed (bigger divider), again till you get it working.
>
> If you are using newlib-lpc, note that in the more recent lpc variants, NXP have changed how the VIC interrupt priorities work, and the clocking/PCLK divider chains, so changes will be required in the system code too if you have one of these.
>
> Cheers,
> Bruce
> -----Original Message-----
> From: l... [mailto:l...] On Behalf Of nerdinrage
> Sent: Thursday, 21 May 2009 4:53 AM
> To: l...
> Subject: [lpc2000] I2C example and winARM LPC2148
>
> I was wondering if anyone could point me towards a working i2c example for winarm. I modified the one from the not ported/tested directory, added rprintf to it to send error messages to the comport. I also fixed the pinsel and iodir issues between rprintf and the i2c header. The communication structure of the chip in the example and the chip I am using are the same. I seem to be getting a I2C not started error and an I2C max timeout exit condition.
>
> Does anyone have any tips or tricks? I am using the embedded artist quickstart + dev board. I did notice that the I2C scl at P0.2 is a bit rounded. I have the Duty cycle and pulse width set per the spec sheet ~400 khz 0.6+us and 1.3+us. Checked and double checked slave and register addresses. The test program I compiled had one read cycle to read reset values of a config register and one write cycle to turn on all the 4 digital outs on the chip.
>
> I had an o-scope on my sda line and while the DAQ chip should have been sending data it looked like:
>
> _⌐⌐⌐⌐⌐_ pretty much idle high with an 87% ish duty cycle
>
>
>
>
>
>
In the embedded artists program the address is 0xA0. I get all day tomorrow to play with the program, took the day off work for a nice four day weekend. I get to walk for my graduation on Sat. though the project isn't done yet. Hopefully I can make some headway tomorrow.

--- In l..., "Bruce Paterson" wrote:
>
> From memory the newlib-lpc driver accepts the actual IIC address. Check that 0xa0 is in fact this, not twice the address (7 addr bits shifted left to allow for R/W bit). You may need to pass 0x50.
>
> Failing that, get out an oscilloscope and look at the IIC lines. Is the device replying with an ack, or nothing at all ?
>
> If the waveforms look quite rounded, try smaller pullup resisters.
>
> Cheers,
> Bruce
> -----Original Message-----
> From: l... [mailto:l...] On Behalf Of nerdinrage
> Sent: Thursday, 21 May 2009 1:57 PM
> To: l...
> Subject: [lpc2000] Re: I2C example and winARM LPC2148
>
> The resisters on the board are 3K as per the embedded artist's spec sheet. The bus is already wired to a I2C eprom, so I thought it would work with another device... but you know I never checked to see if they had the same slave address 0x90. This would be an issue if they are both responding to the same name. ... nope eeprom is 0xa0. I guess I did assume that the file was in an lpc2138/48 folder and that the addresses were correct in the header. Anything off the top of your head I should look at first.
>
> I am new to this whole making sure system files are correct. I suppose my professors were overly kind to me when they gave me equipment that "just works". Oh this is a wonderful learning experience.
>
> There is a point for conversation in there... would it be worthwhile to force students to make things work... you know... instead of handing them known good/operational and patting them on the head when the leds go on and off?
>
> I was shocked to find out that standard library functions weren't supported, or um well defined.
>
> Thanks for the notes I'll see what I can dig up. If anyone wants to jump in and offer some advice I would appreciate it. I'm actually taking some time off of work the first week of june to dive head first into this project. The goal of the 23rd I guess was a bit overzealous.
>
> Thanks
>
>
>
>
>
>
>
>
>
> --- In l..., "Bruce Paterson" wrote:
> >
> > If you are referring to the IIC driver as part of newlib-lpc (in untested on Robert's site), then I wrote this one and it has been serving me well for a few years now. Of course you will need to go through and change hardware specific things for your lpc processor variant, especially things like IOPIN and PINSEL.
> >
> > Ensure the IIC external pullup resisters you have on the IIC bus are low enough in value to get good mostly square waveforms on clock and data. The value will vary dependent on the fan-out of IIC devices and the capacitance of the trackwork. You can always increase them again once you get it working. Try setting the IIC clock speed ridiculously low speed (bigger divider), again till you get it working.
> >
> > If you are using newlib-lpc, note that in the more recent lpc variants, NXP have changed how the VIC interrupt priorities work, and the clocking/PCLK divider chains, so changes will be required in the system code too if you have one of these.
> >
> > Cheers,
> > Bruce
> > -----Original Message-----
> > From: l... [mailto:l...] On Behalf Of nerdinrage
> > Sent: Thursday, 21 May 2009 4:53 AM
> > To: l...
> > Subject: [lpc2000] I2C example and winARM LPC2148
> >
> > I was wondering if anyone could point me towards a working i2c example for winarm. I modified the one from the not ported/tested directory, added rprintf to it to send error messages to the comport. I also fixed the pinsel and iodir issues between rprintf and the i2c header. The communication structure of the chip in the example and the chip I am using are the same. I seem to be getting a I2C not started error and an I2C max timeout exit condition.
> >
> > Does anyone have any tips or tricks? I am using the embedded artist quickstart + dev board. I did notice that the I2C scl at P0.2 is a bit rounded. I have the Duty cycle and pulse width set per the spec sheet ~400 khz 0.6+us and 1.3+us. Checked and double checked slave and register addresses. The test program I compiled had one read cycle to read reset values of a config register and one write cycle to turn on all the 4 digital outs on the chip.
> >
> > I had an o-scope on my sda line and while the DAQ chip should have been sending data it looked like:
> >
> > _⌐⌐⌐⌐⌐_ pretty much idle high with an 87% ish duty cycle
> >
> >
> >
> >
> >
> >
Sorry about that double post my internet connection is a bit shotty at times. Anyway as I was trying to post this. I have been poking around with my oscope turned the clocks down on the I2C bus and popped another probe on to plot the data vs clock. I have a string of 8 1's and a 0 that repeats... a number of times... but no "real" data on the sda line. this sounds like I'm telling it something wrong and it is only transmitting 1's. Any insights?

Sorry no insights.
Can only suggest putting a breakpoint on where the IIC data register is
written to.

Cheers,
Bruce

-----Original Message-----
From: l... [mailto:l...] On Behalf
Of nerdinrage
Sent: Saturday, 23 May 2009 4:25 AM
To: l...
Subject: [lpc2000] Re: I2C example and winARM LPC2148

Sorry about that double post my internet connection is a bit shotty at
times. Anyway as I was trying to post this. I have been poking around
with my oscope turned the clocks down on the I2C bus and popped another
probe on to plot the data vs clock. I have a string of 8 1's and a 0
that repeats... a number of times... but no "real" data on the sda line.
this sounds like I'm telling it something wrong and it is only
transmitting 1's. Any insights?

I've currently built a version and compiled it in Keil Uvision 3, while I'm debugging I notice that the I20STAT changes to case 0x08 but the I2CMasterState never = I2C_STARTED. I'm wondering if I am having issues with my interrupt handler.

/* this handler deals with master read and master write only */
StatValue = I20STAT;
IENABLE; /* handles nested interrupt */
switch ( StatValue )
{
case 0x08: /* A Start condition is issued. */
I20DAT = I2CMasterBuffer[0];
I20CONCLR = (I2CONCLR_SIC | I2CONCLR_STAC);
I2CMasterState = I2C_STARTED;
break;

case 0x10: /* A repeated started is issued */
if ( I2CCmd == GET_DEVICE_ID || I2CCmd == GET_TEMPERATURE )
{
I20DAT = I2CMasterBuffer[2];
}
I20CONCLR = (I2CONCLR_SIC | I2CONCLR_STAC);
I2CMasterState = I2C_RESTARTED;
break;

or does keil debugger not go into irq handlers?

at case 0x08 I2CMasterState = I2C_STARTED; and the if loop for timeout should exit.

--- In l..., "Bruce Paterson" wrote:
>
> Sorry no insights.
> Can only suggest putting a breakpoint on where the IIC data register is
> written to.
>
> Cheers,
> Bruce
>
> -----Original Message-----
> From: l... [mailto:l...] On Behalf
> Of nerdinrage
> Sent: Saturday, 23 May 2009 4:25 AM
> To: l...
> Subject: [lpc2000] Re: I2C example and winARM LPC2148
>
> Sorry about that double post my internet connection is a bit shotty at
> times. Anyway as I was trying to post this. I have been poking around
> with my oscope turned the clocks down on the I2C bus and popped another
> probe on to plot the data vs clock. I have a string of 8 1's and a 0
> that repeats... a number of times... but no "real" data on the sda line.
> this sounds like I'm telling it something wrong and it is only
> transmitting 1's. Any insights?
>
>
I've noticed that I do not make it into the interrupt handler at all. I've tried adding:

VICIntSelect = 0x0
VICIntEnable = 0x200
VICVectAddr0 = (unsigned long) I2C0MasterHandler

still no luck on getting the I2Cengine into the irq handler.

any thoughts?

--- In l..., "nerdinrage" wrote:
>
> I've currently built a version and compiled it in Keil Uvision 3, while I'm debugging I notice that the I20STAT changes to case 0x08 but the I2CMasterState never = I2C_STARTED. I'm wondering if I am having issues with my interrupt handler.
>
> /* this handler deals with master read and master write only */
> StatValue = I20STAT;
> IENABLE; /* handles nested interrupt */
> switch ( StatValue )
> {
> case 0x08: /* A Start condition is issued. */
> I20DAT = I2CMasterBuffer[0];
> I20CONCLR = (I2CONCLR_SIC | I2CONCLR_STAC);
> I2CMasterState = I2C_STARTED;
> break;
>
> case 0x10: /* A repeated started is issued */
> if ( I2CCmd == GET_DEVICE_ID || I2CCmd == GET_TEMPERATURE )
> {
> I20DAT = I2CMasterBuffer[2];
> }
> I20CONCLR = (I2CONCLR_SIC | I2CONCLR_STAC);
> I2CMasterState = I2C_RESTARTED;
> break;
>
>
> or does keil debugger not go into irq handlers?
>
> at case 0x08 I2CMasterState = I2C_STARTED; and the if loop for timeout should exit.
> --- In l..., "Bruce Paterson" wrote:
> >
> > Sorry no insights.
> > Can only suggest putting a breakpoint on where the IIC data register is
> > written to.
> >
> > Cheers,
> > Bruce
> >
> > -----Original Message-----
> > From: l... [mailto:l...] On Behalf
> > Of nerdinrage
> > Sent: Saturday, 23 May 2009 4:25 AM
> > To: l...
> > Subject: [lpc2000] Re: I2C example and winARM LPC2148
> >
> > Sorry about that double post my internet connection is a bit shotty at
> > times. Anyway as I was trying to post this. I have been poking around
> > with my oscope turned the clocks down on the I2C bus and popped another
> > probe on to plot the data vs clock. I have a string of 8 1's and a 0
> > that repeats... a number of times... but no "real" data on the sda line.
> > this sounds like I'm telling it something wrong and it is only
> > transmitting 1's. Any insights?
> >
> >
> >
> >
> >
> >

The 2024 Embedded Online Conference