Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

I2C... Some issue in my code ?

$
0
0

Hi there,

I am currently trying to interface a eeprom through I2C communication interface (USCI) on my msp430g2553.The main parts of my code are pasted here :

I have some issue i my code, impossible in first step to read the current data of my eeprom. It is not an hardware issue because, it works fine on another mcu (PIC !)

So, it is ok for 0x53 slave address and permission to read/write at address 0x00.

Any idea about the i2c code issue ?

BR

GM

PS : impossible to copy/and paste code with colors i e2e community forum....

#include  "msp430g2553.h"

void I2C(void);
unsigned char I2C_read_byte(unsigned char);
void I2C_write_byte(unsigned char, unsigned char);

void main(void){
    WDTCTL = WDTPW + WDTHOLD;    // Stop WTD

    I2C();                 // I2C configuration
    __delay_cycles(2000);        // Wait a little time !
    //I2C_write_byte(0x53, 0xAA);    // Write data
    //__delay_cycles(2000);        // wait a little time more !
    unsigned char toto = I2C_read_byte(0x00);        // Read the data written...

    int tata = 9; //for mspdebug with "info locals"
}

void I2C(void){                // First I2C configuration for MSP430g2553
    UCB0CTL1 |= UCSWRST;        // Go into reset state
    UCB0CTL0 |= UCMST + UCMODE_3 + UCSYNC;// I2C master mode + I2C on USCI + Synchronous mode
    UCB0CTL1 &= ~UCSWRST;        // Release for operation
}

void I2C_write_byte(unsigned char adress, unsigned char data){
    UCB0CTL1 |= UCSWRST;        // Go into reset state
    UCB0I2CSA = adress;        // I2C slave adress    
    UCB0CTL1 |= UCTR + UCTXSTT;     // I2C in transmiter mode + start condition
    UCB0CTL1 &= ~UCSWRST;        // Release for operation

    while (!(IFG2 & UCB0TXIFG));     // Wait for tx to be ready
    UCA0TXBUF = data;        // Write byte data ! ! !

    UCB0CTL1 |= UCSWRST;        // Go into reset state
    UCB0CTL1 |= UCTXSTP;         // I2C stop condition
    UCB0CTL1 &= ~UCSWRST;        // Release for operation
}

unsigned char I2C_read_byte(unsigned char adress){
    UCB0CTL1 |= UCSWRST;        // Go into reset state
    UCB0I2CSA = adress;        // I2C slave adress    
    UCB0CTL1 |= UCTXSTT;     // I2C in recieve mode + start condition
    UCB0CTL1 &= ~UCSWRST;        // Release for operation

    while (!(IFG2 & UCB0RXIFG));     // Wait for tx to be ready
    unsigned char data_read = UCA0RXBUF;        // Write byte data ! ! !

    UCB0CTL1 |= UCSWRST;        // Go into reset state
    UCB0CTL1 |= UCTXSTP;         // I2C stop condition
    UCB0CTL1 &= ~UCSWRST;        // Release for operation

    return data_read;
}

Mspdebug indicate :

Program received signal SIGTRAP, Trace/breakpoint trap.
0x0000c140 in I2C_read_byte (adress=0 '\000') at i2c3.c:45
45        while (!(IFG2 & UCB0RXIFG));     // Wait for tx to be ready
(gdb) info locals
data_read = 0 '\000'


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>