Loading ...
Sorry, an error occurred while loading the content.

Watch the I2C Kommunikation on UART

Expand Messages
  • marcusmoser81
    hi, I have another problem with my ADuC7026. If I want to mirror the I2C Kommunikation on UART. I have connected the I2C1 with pull-up resistors to a ADuC 7020
    Message 1 of 2 , Jun 20, 2006
    • 0 Attachment
      hi,
      I have another problem with my ADuC7026. If I want to mirror the I2C
      Kommunikation on UART.
      I have connected the I2C1 with pull-up resistors to a ADuC 7020 just
      like MArtin Schöneck describe in his topic ( AduC 7026 as a master
      and AduC 7020 as a slave).
      Then I have downloaded the master and the slave code samples from
      analog. I have changed some things in the master.c file. I have
      added a UART output and input function. You can the code here:

      #include"ADuC7020.h"

      void delay(int);
      void My_IRQ_Function(void);
      int write (int file, char *ptr, int len);
      char getchar (void);
      int putchr(char); // write character
      to Serial Por
      void configuration(void);

      #define count 0x4; // Number of bytes
      to be recieved - 1
      #define CR 0x0D
      int i = 0;
      char dat; // Size of dat
      should be (count + 1)



      char getchar (void) // read bytes from
      serial port
      {
      while(!(0x01==(COMSTA0 & 0x01)))
      {}
      return (COMRX);
      }

      int putchr(char ch)
      {

      if (ch == '\n')
      {
      while((0x000==(COMSTA0 & 0x020)))
      {}
      return (COMTX = CR); // output of CR
      }
      else
      {
      while((0x000==(COMSTA0 & 0x020)))
      {}

      return (COMTX = ch);
      }
      }
      int write (int file, char *ptr, int len) // output on
      hyperterminal
      {
      int j;

      for (j = 0; j < len; j++) putchr (*ptr++);
      return len;
      }
      void delay (int length)
      {
      while (length >0)
      length--;
      }
      void My_IRQ_Function(void)
      {
      // Transmit
      if(((I2C1MSTA & 0x4) == 0x4) && (i < 8)) // Master
      Transmit IRQ
      {
      i++; // Transmits
      numbers 1-8
      I2C1MTX = i;
      write(0,"I2C1MTX\n",9); // output on
      hyperterminal
      write(0,&I2C1MTX,2); // output,
      to watch the communication
      }

      // Receive
      if((I2C1MSTA & 0x8) == 0x8) // Master
      Recieve IRQ
      {
      dat = I2C1MRX;
      i++;
      write(0,"I2C1MRX\n",9);
      write(0,&I2C1MRX,2); // output,
      to watch the communication


      }
      }
      void configuration(void)
      {
      // I2C und UART initilalizieren

      GP1CON = 0x2211; // I2C on P1.2 and P1.3 plus
      UART on P1.0 and P1.1

      I2C1CFG = 0x82; // Master Enable & Enable
      Generation of Master Clock

      // I2C-Master setup
      I2C1DIV = 0xCFCF; // 0x3232 = 400kHz
      // 0xCFCF = 100kHz

      IRQ = My_IRQ_Function; // Specify Interrupt Service
      Routine
      IRQEN = 0x400; // I2C1 Master Interupt


      // Start setting up UART at 9600bps
      COMCON0 = 0x080; // Setting
      DLAB
      COMDIV0 = 0x088; // Setting
      DIV0 and DIV1 to DL calculated
      COMDIV1 = 0x000;
      COMCON0 = 0x007; // Clearing
      DLAB

      }




      /****************************MAIN********************************/
      int main(void)
      {

      configuration();

      // output on terminal
      char output1[15] = "Test\n";
      write(0,output1,15); // Output Data



      // Transmit
      I2C1ADR = 0xA0; // set i2c address
      (LSB = 0, Master Write)
      I2C1MTX = 0x55; // send i2c byte
      address
      write(0,&I2C1MTX,2); // output, to watch
      the communication



      delay(1500);

      // Recieve
      i = 0;
      I2C1CNT = count; // Number of bytes
      to be read from slave
      I2C1ADR = 0xA1; // set i2c address
      (LSB = 1, Master Read)




      while (1)
      {

      };

      return 0;
      }




      Now my problem is, I don't see any value in the I2C1MTX or MRX
      registers on hyper terminal. I also have the place down the values
      in a martix, but there is nothing in the matrix.
      Can anyone help me?

      Marcus Moser
    • Andrey
      Hi Marcus. I am also trying to get I2C to work (with some debug output on the UART). I want to warn you about the ADI/Keil examples included and their use
      Message 2 of 2 , Oct 15, 2006
      • 0 Attachment
        Hi Marcus. I am also trying to get I2C to work (with some debug
        output on the UART). I want to warn you about the ADI/Keil 'examples'
        included and their use of the UART, I have a note about it here:

        http://thedotcommune.com/aduc.html

        Our code looks very similar, though in my case the problem is that the
        IRQ routine never runs even though I:
        1) set up the I/O register
        2) enable the I2C interrupt and set up Master mode with TX/RX interrupts
        3) have my transmit send out an address, etc

        I suspect this has something to do with me using Keil-type linker and
        startup code files with a regular GNU toolchain, but I don't really
        see why. Perhaps I am not properly enabling interrupts on the global
        level (i bit). In your case, does your IRQ routine ever run?
      Your message has been successfully submitted and would be delivered to recipients shortly.