This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

i2c lpc2368

There are two sda1 and scl1 on the lpc2368?

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

  • 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

  • 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;

  • 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.

  • 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

  • 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++)
        {
            ;
        }
    }
    
    
    
    

  • 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

  • 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.

  • 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)

  • 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.

  • 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.