November 16, 2024, 06:00:48 PM

CCRF I2C MOD-IO

Started by zeronio, May 26, 2013, 12:56:48 AM

Previous topic - Next topic

zeronio

Hi.

I am trying to do communication between CCRF and MOD-IO via I2C.
My code is based on TI example for sending multiple bytes as i2c master. (cc430x513x_uscib0_i2c_08.c)
Unfortunately nothing happens when I run it.
Has anyone tried to do something like this?


#include <msp430.h>

unsigned char *PTxData;                     // Pointer to TX data
unsigned char TXByteCtr;

const unsigned char TxData[] =              // Table of data to transmit
{
  0x10,  // MOD-IO Digital output command
  0x01   // Switch relay 1 ON
};

int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
 
  PMAPPWD = 0x02D52;                        // Get write-access to port mapping regs 
  P1MAP3 = PM_UCB0SDA;                      // Map UCB0SDA output to P1.3
  P1MAP2 = PM_UCB0SCL;                      // Map UCB0SCL output to P1.2
  PMAPPWD = 0;                              // Lock port mapping registers
 
  P1SEL |= BIT2 + BIT3;                     // Select P1.2 & P1.3 to I2C function
   
  UCB0CTL1 |= UCSWRST;                      // Enable SW reset
  UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;     // I2C Master, synchronous mode
  UCB0CTL1 = UCSSEL_2 + UCSWRST;            // Use SMCLK, keep SW reset
  UCB0BR0 = 12;                             // fSCL = SMCLK/12 = ~100kHz
  UCB0BR1 = 0;
  UCB0I2CSA = 0x58;                         // Slave Address is 048h
  UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation
  UCB0IE |= UCTXIE;                         // Enable TX interrupt

  while (1)
  {
    __delay_cycles(50);                     // Delay required between transaction
    PTxData = (unsigned char *)TxData;      // TX array start address
                                            // Place breakpoint here to see each
                                            // transmit operation.
    TXByteCtr = sizeof TxData;              // Load TX byte counter

    UCB0CTL1 |= UCTR + UCTXSTT;             // I2C TX, start condition

    __bis_SR_register(LPM0_bits + GIE);     // Enter LPM0, enable interrupts
    __no_operation();                       // Remain in LPM0 until all data
                                            // is TX'd
    while (UCB0CTL1 & UCTXSTP);             // Ensure stop condition got sent
  }
}

//------------------------------------------------------------------------------
// The USCIAB0TX_ISR is structured such that it can be used to transmit any
// number of bytes by pre-loading TXByteCtr with the byte count. Also, TXData
// points to the next byte to transmit.
//------------------------------------------------------------------------------
#pragma vector = USCI_B0_VECTOR
__interrupt void USCI_B0_ISR(void)
{
  switch(__even_in_range(UCB0IV,12))
  {
  case  0: break;                           // Vector  0: No interrupts
  case  2: break;                           // Vector  2: ALIFG
  case  4: break;                           // Vector  4: NACKIFG
  case  6: break;                           // Vector  6: STTIFG
  case  8: break;                           // Vector  8: STPIFG
  case 10: break;                           // Vector 10: RXIFG
  case 12:                                  // Vector 12: TXIFG
    if (TXByteCtr)                          // Check TX byte counter
    {
      UCB0TXBUF = *PTxData++;               // Load TX buffer
      TXByteCtr--;                          // Decrement TX byte counter
    }
    else
    {
      UCB0CTL1 |= UCTXSTP;                  // I2C stop condition
      UCB0IFG &= ~UCTXIFG;                  // Clear USCI_B0 TX int flag
      __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
    }
  default: break;
  }
}

zeronio

The first problem is that according to schematics the MODIO UEXT and CCRF UEXT are not compatible.
MODIO has SCL/SDA on pins 3,6 and CCRF has SCL/SDA on pins 5/6... strange... So you can not connect the 2 with the standard UEXT cable.

The UEXT SDA signal on female connector on MODIO has a 4.7K pullup resistor while on there is none on the male connector. Both SCL & SDA on CCRF have 4.7 pullup resistors.
So I used male connector on the MODIO side. I connected GNDs on PIN 2, SDAs on PIN 6 and SCL pin 3 on MODIO to SCL pin 5 on CCRF.
But still nothing.

LubOlimex

Hey Zeronio,

The SCL/SDA are on the same UEXT pins 5-6. The problem is in the .pdf export from the eagle source file that shifted the entire column up by one position.

Best regards,
Lub/OLIMEX
Technical support and documentation manager at Olimex