EmbeddedRelated.com
Forums

LPC1114 I2C Problem

Started by r_goncalves2000 May 29, 2012
I also use a UART and set the baud rate by the SystemCoreClock and
everything works ok.
I send by the UART the value of SystemCoreClock and is 50MHz (I use a
10MHz crystal and PLL).
I callSystemCoreClockUpdate() before as you sugestedbut there was no
chamges.
Thanks

Citando Daniel Widyanto :
>
>
>
> Hi,
>
> If you useSystemCoreClock(as inLPC_I2C->SCLH =
> (SystemCoreClock / 400000UL)), make sure you have called
> theSystemCoreClockUpdate() before. Otherwise,
> theSystemCoreClockwill showed 12Mhz, even though your MCU clock
> already configured to run at 48Mhz.
>
> Regards,
> -daniel
> ________________________________
> From: M. Manca
> To: l...[2]
> Sent: Thursday, May 31, 2012 2:33 AM
> Subject: Re: [lpc2000] LPC1114 I2C Problem
>
> Il 30/05/2012 19:15, r...@iol.pt[3] ha scritto:
> >
> >
> > Still doesn't work.
> > Thanks.
> >
> Is your hw proprietary or are you using some evaluation board? May you
> be interested to have a working example on a standard board?
> What IDE/compiler are you using?
> >
> >
> > Citando Phil Young > > >:
> > >
> > >
> > >
> > > Try this setting for the PIO control pins, I use it and it
> works fine.
> > >
> > > LPC_IOCON->PIO0_4 = 0xC1U; /* P0.4 = SCL */
> > > LPC_IOCON->PIO0_5 = 0xC1U; /* P0.5 = SDA */
> > >
> > > Regards
> > >
> > > Phil.
> > >
> > > From: l...[2]
> [1]
> > > [mailto:l...[2]
> > [1]] On Behalf Of
> > > r_goncalves2000
> > > Sent: 29 May 2012 18:14
> > > To: l...[2]
> [1]
> > > Subject: [lpc2000] LPC1114 I2C Problem
> > >
> > > (I've posted this message to LP1100 group but it was my
> > > intention to post
> > > anly here. Sorry)
> > >
> > > Hello All
> > > I'm having a bad time trying to communicate with a 24LC16 E2PROM.
> > > I've done this before with LPC2000 and LPC17xx micros with no
> > > problem, and
> > > it
> > > was no big deal.
> > > After a couple of days with this problem I'm running out of
> > > ideas on how to
> > > solve the problem and don't know if it's a software or
> > > hardware problem.
> > >
> > > My hardware is as follow:
> > > - LPC1114 pin 16 (SDA) connects to 24LC16 pin 5 (SDA)
> > > - LPC1114 pin 15 (SCL) connects to 24LC16 pin 6 (SCL)
> > > - Each line as a 2K7 pull-up resistor to 3V3
> > > - The board is a 4 layer board and the 24LC16 is 1cm away
> from the MCU.
> > >
> > > My I2C initialization routine for 400KHz is as follows:
> > > NVIC_DisableIRQ( I2C_IRQn ); /* Disable I2C-bus interrupts */
> > > g_ui32I2C_Flags = 0;
> > > LPC_SYSCON->PRESETCTRL |= 0x02U; /* De-assert the reset */
> > > LPC_SYSCON->SYSAHBCLKCTRL |= (0x01U << 5); /* Enable I2C clock */
> > > LPC_IOCON->PIO0_4 = 0x01U; /* P0.4 = SCL */
> > > LPC_IOCON->PIO0_5 = 0x01U; /* P0.5 = SDA */
> > > LPC_I2C->CONCLR = 0x6CU; /* Clear all I2C operation bits */
> > > LPC_I2C->SCLH = (SystemCoreClock / 400000UL);
> > > LPC_I2C->SCLH >>= 1U; /* Divide value by 2 (duty cycle of 50%) */
> > > if( LPC_I2C->SCLH < 4U )
> > > {
> > > LPC_I2C->SCLH = 4U; /* Value must be bigger than or equal to 4 */
> > > }
> > > LPC_I2C->SCLL = LPC_I2C->SCLH; /* Duty cycle of 50% */
> > > NVIC_EnableIRQ( I2C_IRQn ); /* Enable I2C-bus interface
> interrupts */
> > > LPC_I2C->CONSET = 0x40U; /* Enable I2C interface */
> > >
> > > At 400KHz I can't read nor write.
> > > I've tried 10KHz and most of the times I can read but most of
> > > the times I
> > > can't
> > > write.
> > > I know the I2C ISR is beeing trigered.
> > > I increment counters for each interruption an I can see that some
> > > interruptions
> > > are beeing fired.
> > >
> > > Any ideas to find were the problem is?
> > >
> > > Thanks.
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> > Ligaes:
> > ---------
> > [1] mailto:lpc2000%40yahoogroups.com
> > [2]
> > mailto:p...@dsl.pipex.com[4]
> >
> ?subject=RE%3A%20%5Blpc2000%5D%20LPC1114%20I2C%20Problem
> > [3]
> > mailto:l...[2]
> >
> ?subject=RE%3A%20%5Blpc2000%5D%20LPC1114%20I2C%20Problem
> > [4]
> >
> http://groups.yahoo.com/group/lpc2000/post;_ylc=X3oDMTJybTdpNzlhBF9TAzk3MzU5NzE0BGdycElkAzExNDUzMTY2BGdycHNwSWQDMTcwNjU1NDIwNQRtc2dJZAM1NzQxOARzZWMDZnRyBHNsawNycGx5BHN0aW1lAzEzMzgzMTU0NjI-?act=reply&messageNum=57418
> >
>
> > [5]
> >
> http://groups.yahoo.com/group/lpc2000/post;_ylc=X3oDMTJmdXJxYjUyBF9TAzk3MzU5NzE0BGdycElkAzExNDUzMTY2BGdycHNwSWQDMTcwNjU1NDIwNQRzZWMDZnRyBHNsawNudHBjBHN0aW1lAzEzMzgzMTU0NjI-
> > [6]
> >
> http://groups.yahoo.com/group/lpc2000/message/57416;_ylc=X3oDMTM3djU2Nm0xBF9TAzk3MzU5NzE0BGdycElkAzExNDUzMTY2BGdycHNwSWQDMTcwNjU1NDIwNQRtc2dJZAM1NzQxOARzZWMDZnRyBHNsawN2dHBjBHN0aW1lAzEzMzgzMTU0NjIEdHBjSWQDNTc0MTY-
> > [7]
> >
> http://groups.yahoo.com/group/lpc2000/members;_ylc=X3oDMTJnbWdzcTc5BF9TAzk3MzU5NzE0BGdycElkAzExNDUzMTY2BGdycHNwSWQDMTcwNjU1NDIwNQRzZWMDdnRsBHNsawN2bWJycwRzdGltZQMxMzM4MzE1NDYy?o=6
> > [8]
> >
> http://groups.yahoo.com/group/lpc2000;_ylc=X3oDMTJmZjlqajhvBF9TAzk3MzU5NzE0BGdycElkAzExNDUzMTY2BGdycHNwSWQDMTcwNjU1NDIwNQRzZWMDdnRsBHNsawN2Z2hwBHN0aW1lAzEzMzgzMTU0NjI-
> > [9]
> >
> http://groups.yahoo.com/;_ylc=X3oDMTJlMHQxODBoBF9TAzk3MzU5NzE0BGdycElkAzExNDUzMTY2BGdycHNwSWQDMTcwNjU1NDIwNQRzZWMDZnRyBHNsawNnZnAEc3RpbWUDMTMzODMxNTQ2Mg--
> > [10]
> > mailto:l...[5]
> >
> ?subject=Change%20Delivery%20Format:%20Traditional
> > [11] mailto:l...[6]
> >
> ?subject=Email%20Delivery:%20Digest
> > [12] mailto:l...[7]
> > ?subject=Unsubscribe
> > [13] http://docs.yahoo.com/info/terms/
> >
> >
> >
> >
>
>
>
>


An Engineer's Guide to the LPC2100 Series

That was not the problem.
But thank you very much to point this issue to my attention.
Thisis the type of thing that when happens cantaketime to discover.
I will take extra care in the future writing to registers.

Citando bigft_id :
> I looked at your code, and I am not surprised... :-) Your tidbit
> below may write all kinds of stuff into LPC_I2C->SCLH. Using a
> peripheral register as general variable is bad form... sometimes
> writing bad value hangs the whole peripheral. Try:
>
> unsigned long CookingTheClock = SystemCoreClock / 8000000;
> if ( CookingTheClock < 4 )
> CookingTheClock = 4;
>
> LPC_I2C->SCLH = CookingTheClock;
> LPC_I2C->SCLH = CookingTheClock;
>
> and see if that works...
>> LPC_I2C->SCLH = (SystemCoreClock / 400000UL);
>> LPC_I2C->SCLH >>= 1U; /* Divide value by 2 (duty cycle of 50%) */
>> if( LPC_I2C->SCLH < 4U )
>> {
>> LPC_I2C->SCLH = 4U; /* Value must be bigger than or equal to 4 */
>> }
>> LPC_I2C->SCLL = LPC_I2C->SCLH; /* Duty cycle of 50% */
> --- In l..., Daniel Widyanto
> wrote: > Hi,
>>
>> If you use�SystemCoreClock�(as in�LPC_I2C->SCLH =
>> (SystemCoreClock / 400000UL)�), make sure you have called
>> the�SystemCoreClockUpdate() before. Otherwise,
>> the�SystemCoreClock�will showed 12Mhz, even though your MCU
>> clock already configured to run at 48Mhz.
>>
>> Regards,
>> -daniel
>> ________________________________
>> From: M. Manca
>> To: l...
>> Sent: Thursday, May 31, 2012 2:33 AM
>> Subject: Re: [lpc2000] LPC1114 I2C Problem
>>
>> Il 30/05/2012 19:15, rpsgoncalves@... ha scritto:
>> �
>>
>> Still doesn't work.
>> Thanks.
>>
>> Is your hw proprietary or are you using some evaluation board? May you
>> be interested to have a working example on a standard board?
>> What IDE/compiler are you using?
>> Citando Phil Young >> >:
>> >
>> >�
>> >
>> > Try this setting for the PIO control pins, I use it and it works fine.
>> >
>> > LPC_IOCON->PIO0_4 = 0xC1U; /* P0.4 = SCL */
>> > LPC_IOCON->PIO0_5 = 0xC1U; /* P0.5 = SDA */
>> >
>> > Regards
>> >
>> > Phil.
>> >
>> > From: l... [1]
>> > [mailto:l...
>> [1]] On Behalf Of
>> > r_goncalves2000
>> > Sent: 29 May 2012 18:14
>> > To: l... [1]
>> > Subject: [lpc2000] LPC1114 I2C Problem
>> >
>> > (I've posted this message to LP1100 group but it was my
>> > intention to post
>> > anly here. Sorry)
>> >
>> > Hello All
>> > I'm having a bad time trying to communicate with a 24LC16 E2PROM.
>> > I've done this before with LPC2000 and LPC17xx micros with no
>> > problem, and
>> > it
>> > was no big deal.
>> > After a couple of days with this problem I'm running out of
>> > ideas on how to
>> > solve the problem and don't know if it's a software or
>> > hardware problem.
>> >
>> > My hardware is as follow:
>> > - LPC1114 pin 16 (SDA) connects to 24LC16 pin 5 (SDA)
>> > - LPC1114 pin 15 (SCL) connects to 24LC16 pin 6 (SCL)
>> > - Each line as a 2K7 pull-up resistor to 3V3
>> > - The board is a 4 layer board and the 24LC16 is 1cm away from the MCU.
>> >
>> > My I2C initialization routine for 400KHz is as follows:
>> > NVIC_DisableIRQ( I2C_IRQn ); /* Disable I2C-bus interrupts */
>> > g_ui32I2C_Flags = 0;
>> > LPC_SYSCON->PRESETCTRL |= 0x02U; /* De-assert the reset */
>> > LPC_SYSCON->SYSAHBCLKCTRL |= (0x01U << 5); /* Enable I2C clock */
>> > LPC_IOCON->PIO0_4 = 0x01U; /* P0.4 = SCL */
>> > LPC_IOCON->PIO0_5 = 0x01U; /* P0.5 = SDA */
>> > LPC_I2C->CONCLR = 0x6CU; /* Clear all I2C operation bits */
>> > LPC_I2C->SCLH = (SystemCoreClock / 400000UL);
>> > LPC_I2C->SCLH >>= 1U; /* Divide value by 2 (duty cycle of 50%) */
>> > if( LPC_I2C->SCLH < 4U )
>> > {
>> > LPC_I2C->SCLH = 4U; /* Value must be bigger than or equal to 4 */
>> > }
>> > LPC_I2C->SCLL = LPC_I2C->SCLH; /* Duty cycle of 50% */
>> > NVIC_EnableIRQ( I2C_IRQn ); /* Enable I2C-bus interface interrupts */
>> > LPC_I2C->CONSET = 0x40U; /* Enable I2C interface */
>> >
>> > At 400KHz I can't read nor write.
>> > I've tried 10KHz and most of the times I can read but most of
>> > the times I
>> > can't
>> > write.
>> > I know the I2C ISR is beeing trigered.
>> > I increment counters for each interruption an I can see that some
>> > interruptions
>> > are beeing fired.
>> >
>> > Any ideas to find were the problem is?
>> >
>> > Thanks.
>> >
>> >
>> >�
>> >
>> >
>> >
>> >
>>
>> Liga��es:
>> ---------
>> [1] mailto:lpc2000%40yahoogroups.com
>> [2]
>> mailto:philipjyoung@...
>>
>> ?subject=RE%3A%20%5Blpc2000%5D%20LPC1114%20I2C%20Problem
>> [3]
>> mailto:l...
>>
>> ?subject=RE%3A%20%5Blpc2000%5D%20LPC1114%20I2C%20Problem
>> [4]
>> http://groups.yahoo.com/group/lpc2000/post;_ylc=X3oDMTJybTdpNzlhBF9TAzk3MzU5NzE0BGdycElkAzExNDUzMTY2BGdycHNwSWQDMTcwNjU1NDIwNQRtc2dJZAM1NzQxOARzZWMDZnRyBHNsawNycGx5BHN0aW1lAzEzMzgzMTU0NjI-?act=reply&messageNum=57418
>>
>>
>> [5]
>> http://groups.yahoo.com/group/lpc2000/post;_ylc=X3oDMTJmdXJxYjUyBF9TAzk3MzU5NzE0BGdycElkAzExNDUzMTY2BGdycHNwSWQDMTcwNjU1NDIwNQRzZWMDZnRyBHNsawNudHBjBHN0aW1lAzEzMzgzMTU0NjI-
>> [6]
>> http://groups.yahoo.com/group/lpc2000/message/57416;_ylc=X3oDMTM3djU2Nm0xBF9TAzk3MzU5NzE0BGdycElkAzExNDUzMTY2BGdycHNwSWQDMTcwNjU1NDIwNQRtc2dJZAM1NzQxOARzZWMDZnRyBHNsawN2dHBjBHN0aW1lAzEzMzgzMTU0NjIEdHBjSWQDNTc0MTY-
>> [7]
>> http://groups.yahoo.com/group/lpc2000/members;_ylc=X3oDMTJnbWdzcTc5BF9TAzk3MzU5NzE0BGdycElkAzExNDUzMTY2BGdycHNwSWQDMTcwNjU1NDIwNQRzZWMDdnRsBHNsawN2bWJycwRzdGltZQMxMzM4MzE1NDYy?o=6
>> [8]
>> http://groups.yahoo.com/group/lpc2000;_ylc=X3oDMTJmZjlqajhvBF9TAzk3MzU5NzE0BGdycElkAzExNDUzMTY2BGdycHNwSWQDMTcwNjU1NDIwNQRzZWMDdnRsBHNsawN2Z2hwBHN0aW1lAzEzMzgzMTU0NjI-
>> [9]
>> http://groups.yahoo.com/;_ylc=X3oDMTJlMHQxODBoBF9TAzk3MzU5NzE0BGdycElkAzExNDUzMTY2BGdycHNwSWQDMTcwNjU1NDIwNQRzZWMDZnRyBHNsawNnZnAEc3RpbWUDMTMzODMxNTQ2Mg--
>> [10]
>> mailto:l...
>>
>> ?subject=Change%20Delivery%20Format:%20Traditional
>> [11] mailto:l...
>>
>> ?subject=Email%20Delivery:%20Digest
>> [12] mailto:l...
>> ?subject=Unsubscribe
>> [13] http://docs.yahoo.com/info/terms/
>>
>>
>>
>>
>>
>>
>>
>>
Thanks Phil

This is good advise.

I solved the problem.
Aparently it was not software but hardware.
I was developing the software in one board, aparently that board was bad.
I then tried the software on a second board, but the software was
changed and didn't work so I thought the problem was software.
I decided to start again with the unchanged software on a new board and
it start working as expected.

Thanks also to Manca and Alexan_e for the suport.

Rui

Citando Phil Young :
>
>
>
> The easiest thing for you to do is download the Keil tools, you can get a
> free license that is limited by code size but is big enough
> for any LPC1114
> project.
>
> Then compile your code and run it in the simulator, that will
> let you single
> step and view all the peripherals as simulated blocks, and
> also give you
> detailed status displays for them including clock frequency etc.
>
> It should then be instantly apparent what you are doing wrong.
>
> Regards
>
> Phil.
>
> -----Original Message-----
> From: l...[1]
> [mailto:l...[1]] On Behalf Of
> r...@iol.pt[2]
> Sent: 30 May 2012 18:21
> To: l...[1]
> Subject: Re: [lpc2000] Re: LPC1114 I2C Problem
>
> I could not determine that because I can not see the clock.
>
> I try to defineP0.4 and P0.5 as outputs but could not toggle them in a
> timer!
> But after setting them to outputsand can set them high or low, but no
> toggle in a timer, but I can toglle a led whit no problem!
> This week is a complete disaster!
>
> Could it be something related to the compilation?
> I tried another board with an LPC11C14 and the behaviour is different
> but it doesn't no work.
>
> Citando Kevin :
> >
> >
> >
> > Have you confirmed that your bitrate is good, you can check with
> > either an logic analyzer or an oscilloscope.
> > Check if the rate and size of your clock pulses are good.
> >
> > --- In l...[1][1], "r_goncalves2000"
> > wrote:
> > >
> > > (I've posted this message to LP1100 group but it was my
> > intention to post anly here. Sorry)
> > >
> > > Hello All
> > > I'm having a bad time trying to communicate with a 24LC16 E2PROM.
> > > I've done this before with LPC2000 and LPC17xx micros with no
> > problem, and it
> > > was no big deal.
> > > After a couple of days with this problem I'm running out of
> > ideas on how to
> > > solve the problem and don't know if it's a software or
> > hardware problem.
> > >
> > > My hardware is as follow:
> > > - LPC1114 pin 16 (SDA) connects to 24LC16 pin 5 (SDA)
> > > - LPC1114 pin 15 (SCL) connects to 24LC16 pin 6 (SCL)
> > > - Each line as a 2K7 pull-up resistor to 3V3
> > > - The board is a 4 layer board and the 24LC16 is 1cm away from
> > the MCU.
> > >
> > > My I2C initialization routine for 400KHz is as follows:
> > > NVIC_DisableIRQ( I2C_IRQn ); /* Disable I2C-bus interrupts */
> > > g_ui32I2C_Flags = 0;
> > > LPC_SYSCON->PRESETCTRL |= 0x02U; /* De-assert the reset */
> > > LPC_SYSCON->SYSAHBCLKCTRL |= (0x01U << 5); /* Enable I2C clock */
> > > LPC_IOCON->PIO0_4 = 0x01U; /* P0.4 = SCL */
> > > LPC_IOCON->PIO0_5 = 0x01U; /* P0.5 = SDA */
> > > LPC_I2C->CONCLR = 0x6CU; /* Clear all I2C operation bits */
> > > LPC_I2C->SCLH = (SystemCoreClock / 400000UL);
> > > LPC_I2C->SCLH >>= 1U; /* Divide value by 2 (duty cycle of 50%) */
> > > if( LPC_I2C->SCLH < 4U )
> > > {
> > > LPC_I2C->SCLH = 4U; /* Value must be bigger than or equal to 4 */
> > > }
> > > LPC_I2C->SCLL = LPC_I2C->SCLH; /* Duty cycle of 50% */
> > > NVIC_EnableIRQ( I2C_IRQn ); /* Enable I2C-bus interface interrupts
> */
> > > LPC_I2C->CONSET = 0x40U; /* Enable I2C interface */
> > >
> > > At 400KHz I can't read nor write.
> > > I've tried 10KHz and most of the times I can read but most of
> > the times I can't
> > > write.
> > > I know the I2C ISR is beeing trigered.
> > > I increment counters for each interruption an I can see that
> > some interruptions
> > > are beeing fired.
> > >
> > > Any ideas to find were the problem is?
> > >
> > > Thanks.
> > >
> >
> >
> >
> >
> > Ligações:
> ---------
> [1] mailto:lpc2000%40yahoogroups.com
> [2]
> mailto:l...@slomotion.nl[3]?subject=Re%3A%20LPC1114%20I2C%20Problem
> [3]
> mailto:l...[1]?subject=Re%3A%20LPC1114%20I2C%20Problem
> [4]
> http://groups.yahoo.com/group/lpc2000/post;_ylc=X3oDMTJybnYxMzU5BF9TAzk3MzU5
>
> NzE0BGdycElkAzExNDUzMTY2BGdycHNwSWQDMTcwNjU1NDIwNQRtc2dJZAM1NzQxNwRzZWMDZnRy
> BHNsawNycGx5BHN0aW1lAzEzMzgzMTI1MTY-?act=reply&messageNum=57417
> [5]
> http://groups.yahoo.com/group/lpc2000/post;_ylc=X3oDMTJma2tjM2VkBF9TAzk3MzU5
>
> NzE0BGdycElkAzExNDUzMTY2BGdycHNwSWQDMTcwNjU1NDIwNQRzZWMDZnRyBHNsawNudHBjBHN0
> aW1lAzEzMzgzMTI1MTY-
> [6]
> http://groups.yahoo.com/group/lpc2000/message/57416;_ylc=X3oDMTM3YXQyOTFpBF9
>
> TAzk3MzU5NzE0BGdycElkAzExNDUzMTY2BGdycHNwSWQDMTcwNjU1NDIwNQRtc2dJZAM1NzQxNwR
> zZWMDZnRyBHNsawN2dHBjBHN0aW1lAzEzMzgzMTI1MTYEdHBjSWQDNTc0MTY-
> [7]
> http://groups.yahoo.com/group/lpc2000/members;_ylc=X3oDMTJna2w4MmEzBF9TAzk3M
>
> zU5NzE0BGdycElkAzExNDUzMTY2BGdycHNwSWQDMTcwNjU1NDIwNQRzZWMDdnRsBHNsawN2bWJyc
> wRzdGltZQMxMzM4MzEyNTE2?o=6
> [8]
> http://groups.yahoo.com/group/lpc2000;_ylc=X3oDMTJmbHJtMjZ2BF9TAzk3MzU5NzE0B
>
> GdycElkAzExNDUzMTY2BGdycHNwSWQDMTcwNjU1NDIwNQRzZWMDdnRsBHNsawN2Z2hwBHN0aW1lA
> zEzMzgzMTI1MTY-
> [9]
> http://groups.yahoo.com/;_ylc=X3oDMTJlM2RpZnEyBF9TAzk3MzU5NzE0BGdycElkAzExND
>
> UzMTY2BGdycHNwSWQDMTcwNjU1NDIwNQRzZWMDZnRyBHNsawNnZnAEc3RpbWUDMTMzODMxMjUxNg
> --
> [10]
>
> mailto:l...[4]?subject=Change%20Delivery%20Forma
> t:%20Traditional
> [11]
>
> mailto:l...[5]?subject=Email%20Delivery:%20Digest
> [12] mailto:l...[6]?subject=Unsubscribe
> [13] http://docs.yahoo.com/info/terms/
>
>
>
>
>
>