Discussion Forum

i2c lpc2368

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
chris gerretsen
Posted
6-Feb-2010 16:44 GMT
Toolset
ARM
New! i2c lpc2368

There are two sda1 and scl1 on the lpc2368?

And does anyone know the difference in pinsel between the two?

Read-Only
Author
Andy Neil
Posted
6-Feb-2010 16:53 GMT
Toolset
ARM
New! duplicate thread!

http://www.keil.com/forum/docs/thread16344.asp

Read-Only
Author
chris gerretsen
Posted
6-Feb-2010 17:04 GMT
Toolset
ARM
New! RE: duplicate thread!

Yes,two threads meaning the same thing.Question still remains though.

I have the user manual but I am a beginner in this sort of thing.I have working code to use the lpc2368 with channel 1.But as you may have seen there multiple channel 1's.I need to use the channel 1 that corresponds to pin 83 and 85 however I am unsure as to what Pinsel to use:

ICIntSelect &= ~(1<<19); //Set to FIQ '1' or VIC '0' VICVectAddr19 = (unsigned long)I2CISR; // Set Interrupt Vector VICVectPriority19 = 3; // Set priority level to 9 VICIntEnable |= (1<<19); //Enable the interrupt channel in the VIC

PINSEL0 = 0x0000000F; //Switch GPIO to I2C pins I21SCLH = 0x08; //Set bit rate to 57.6 KHz // 14.7456Mhz/VPBDIV+SCLH+SCLL = 14.7456/4+8+8 = 57.6Khz I21SCLL = 0x08;

The above is the code I have but if I want to use the other channel 1 this code does not work.

Is there any advice??

Many thanks

Read-Only
Author
chris gerretsen
Posted
6-Feb-2010 17:08 GMT
Toolset
ARM
New! RE: duplicate thread!

Sorry,that is the interrupt enable and switching GPIO pins to i2c pins for channel 1.

I want to use the other channel but do not know how this code gets changed,particularly the PINSEL0

VICIntSelect &= ~(1<<19); //Set to FIQ '1' or VIC '0' VICVectAddr19 = (unsigned long)I2CISR; // Set Interrupt Vector
VICVectPriority19 = 3; // Set priority level to 9 VICIntEnable |= (1<<19); //Enable the interrupt channel in the VIC

PINSEL0 = 0x0000000F; //Switch GPIO to I2C pins I21SCLH = 0x08; //Set bit rate to 57.6 KHz // 14.7456Mhz/VPBDIV+SCLH+SCLL = 14.7456/4+8+8 = 57.6Khz I21SCLL = 0x08;

Read-Only
Author
John Linq
Posted
8-Feb-2010 01:10 GMT
Toolset
ARM
New! RE: duplicate thread!

There are two sda1 and scl1 on the lpc2368?

No.

Which page in the user manual are you talking about?

Please use proper HTML tag (pre tag) to post your code.

Read-Only
Author
John Linq
Posted
8-Feb-2010 01:12 GMT
Toolset
ARM
New! RE: duplicate thread!

About pre tag:

http://www.danlhenry.com/caps/keil_code.png

Read-Only
Author
chris gerretsen
Posted
8-Feb-2010 10:35 GMT
Toolset
ARM
New! RE: duplicate thread!

Thanks for the reply.

Its basically page 115-158 in the lpc23XX usermanual.The board I have is the mcb2300 version 3.I assumed sda1 and scl1 were pin 85 and 83 as this is what the board schematic showed.However at the end of the schematic it has another lpc diagram,that of the lpc2368FBD100 which i believe is the actual one on my board and this diagram shows sda1 and scl1 as pin 46 and pin 47.It does seem in many mcb schematics that there are infact multiple sda 1 and scl 1 's.

One more point I am confused on is in the actual code.When using pinsel,for example

pinsel0=0x0000000F //How do you know what value to give it?

Many Thanks for any advice

Read-Only
Author
chris gerretsen
Posted
8-Feb-2010 10:43 GMT
Toolset
ARM
New! RE: duplicate thread!

This is my code for channel 1 .Now I am trying to use channel 1 but the other channel 1 and the same code does not work,again I am using the mcb2300 version 3.

This code below does work but on a different variation of the board I have,still with a lpc2368 however.



#include <LPC23xx.H>
#include <stdio.h>


unsigned char arry[2];
void I2CISR (void)      __irq ;                                                                                                                                                 //I2C interrupt routine
void LED_Flash(void);
void Delay(void);

//Background call to start master send and receive byte transf
void I2CTransferByte(unsigned char  Addr);//,unsigned char Data);

unsigned char   *I2CData,
                                I2Counter,
                                I2CAddress;

int main(void)
{
  VICIntSelect  &= ~(1<<19);                             //Set to FIQ '1' or VIC '0'
    VICVectAddr19  = (unsigned long)I2CISR;        // Set Interrupt Vector
    VICVectPriority19  = 3;                         // Set priority level to 9
    VICIntEnable        |= (1<<19);                          //Enable the interrupt channel in the VIC

    PINSEL0      = 0x0000000F;                                  //Switch GPIO to I2C pins
    I21SCLH      = 0x08;                                                //Set bit rate to 57.6 KHz // 14.7456Mhz/VPBDIV+SCLH+SCLL = 14.7456/4+8+8 = 57.6Khz
    I21SCLL      = 0x08;



          arry[0]=0x00;
          arry[1]=0x00;
          I2Counter =2;                  //configure all bits to o/p
          I2CTransferByte(0x40);                //0x40 is Port Expander

      Delay();

    while(1)
    {
          arry[0]=0x09;
          arry[1]=0x00;
          I2Counter =2;
          I2CTransferByte(0x40);

              Delay();

          arry[0]=0x09;
          arry[1]=0xFF;
          I2Counter =2;
          I2CTransferByte(0x40);

              Delay();
    }
}


void I2CTransferByte(unsigned char Addr)//,* unsigned char Data)
{


I2CAddress = Addr; // Place address and data in Globals to be used by  the interrupt
//I2CData    = Data;

I21CONCLR  = 0x000000FF; // Clear all I2C settings
I21CONSET  = 0x00000040; // Enable the I2C interface
I21CONSET  = 0x00000020; // Start condition
}



/*i2c Routine for TC1321 DAC*/

void I2CISR (void)      __irq                                           //I2C interrupt routine
{
    static int index = 0;

  switch (I21STAT) // Read result code and switch to next action
  {
    case (0x08): // Start bit
      I21CONCLR = 0x20; // Clear start bit
      I21DAT = I2CAddress;//&0x7f; // Send address and write bit '0'
      index =0;

    break;

    case (0x18): // Slave address+W, ACK
      I21DAT = arry[index++]; // Write condition for TC1312 = 0x00 Write data to TX register
      I2Counter--;
    break;

    case (0x20): // Slave address +W, Not ACK
      I21DAT = I2CAddress; // Resend address and write bit
    break;

    case (0x28): // Data sent, Ack

       if(I2Counter--!=0)
           {
             I21DAT =arry[index++];
           }
           else
           {
             I21CONSET = 0x10; // Stop condition

       }
    break;
     default :
   break;
  }


  I21CONCLR = 0x08; // Clear I2C interrupt flag
  VICVectAddr = 0x00000000; // Clear interrupt in

}





void Delay(void)
{
    int x;
    for(x = 0; x < 100000; x++)
    {
        ;
    }
}



Read-Only
Author
John Linq
Posted
9-Feb-2010 01:10 GMT
Toolset
ARM
New! RE: duplicate thread!

I am not a hardware guy, and my English ability is not good.

1. There is only one SDA1/SCL1, but they can be configured/connected to different pins.

2. It is your responsibility to find out which pins on your board are the SDA1/SCL1.

3. Assuming that, you are using LPC2368FBD100, and SDA1 and SCL1 are connected to pin-46 and pin-47, then you should look at

5.1.1 100-pin packages

Table 93. Pin function select register 0
(PINSEL0 - address 0xE002 C000) bit description
(LPC2364/65/66/67/68 and LPC2387)

This table tells you how to set PINSEL0

Read-Only
Author
John Linq
Posted
9-Feb-2010 01:14 GMT
Toolset
ARM
New! RE: duplicate thread!

This code below does work but on a different variation of the board I have

It is your responsibility to find out what is the difference, and then modify the code to conform to the hareware design.

Read-Only
Author
John Linq
Posted
9-Feb-2010 01:48 GMT
Toolset
ARM
New! RE: duplicate thread!

Chapter 9: LPC23XX Pin connect block

5.1.1 100-pin packages

Table 93. Pin function select register 0
(PINSEL0 - address 0xE002 C000) bit description
(LPC2364/65/66/67/68 and LPC2387)

Read-Only
Author
chris gerretsen
Posted
9-Feb-2010 21:27 GMT
Toolset
ARM
New! RE: duplicate thread!

Thanks for your attempt.

Unfortunately something that a programming guy i spoke to last week forgot to tell me (something he did know too) was that on the mcb2300 you do have multiple channel 1's for i2c however both are being used.They are wired to various other things such as the output for uart etc as these channels can have multiple uses (4 uses) so infact the only channel of any use to connect devices too on the mcb2300 is sda 0 and scl 0.

Problem solved.

Read-Only
Author
chris gerretsen
Posted
9-Feb-2010 21:29 GMT
Toolset
ARM
New! RE: duplicate thread!

Thanks for your attempt.

Unfortunately something that a programming guy i spoke to last week forgot to tell me (something he did know too) was that on the mcb2300 you do have multiple channel 1's for i2c however both are being used.They are wired to various other things such as the output for uart etc as these channels can have multiple uses (4 uses) so infact the only channel of any use to connect devices too on the mcb2300 is sda 0 and scl 0.

Problem solved.

Next Thread | Thread List | Previous Thread Start a Thread | Settings