Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Yet another I2C newbie having problems

$
0
0

Hey gang,

 

I'm slowly working my way towards supreme greatness and world-overlord status, but before I achieve that I thought I would set up some working tools in my toolbelt. So among the first things I wanted was a Pimmel-proof I2C setup. I'm using an MSP430g2553 chip, and I found some sample code that @_Murphy_ created found here [1]. Paired with the wonderful serial printf combo found in this thread [2], I thought I had the makings of the awesomeness that is me. I soldered up a simple version of the 3eeprom board found on dangerousprototypes [3], tested it with a bus pirate to ensure it works and set about to conquer the world with my g2553 chip.

 

Below is my simple little test program that aims to replicate the test case of the DP 3EEPROM.

#include <msp430.h>
#include "I2C_MSP430.h"
#include "serial.h"

void printf(char *, ...);

void main(void)
{
    char c;
    //uint8_t dev_address = 0xa0;
    uint8_t dev_address = 0b10100000;
    uint8_t reg_address = 0x00;
    uint8_t data[3];
		int i;

    // Disable watchdog 
    WDTCTL = WDTPW + WDTHOLD;

    // Use 1 MHz DCO factory calibration
    DCOCTL = 0;
    BCSCTL1 = CALBC1_1MHZ;
    DCOCTL = CALDCO_1MHZ;
            
    // Setup the serial port
    // Serial out: P1.1 (BIT1)
    // Serial in:  P1.2 (BIT2)
    // Bit rate:   9600 (CPU freq / bit rate)  
    serial_setup (BIT1, BIT2, 1000000 / 9600);
    
    // Send a string

    printf("Write some bytes...\r\n");
    I2CbeginTransmission(dev_address);
    I2Cwrite(0);
    I2Cwrite(0);
    I2Cwrite(3);
    I2Cwrite(2);
    I2Cwrite(1);
    I2CendTransmission();
    
    printf("Move read pointer...\r\n");
    I2CbeginTransmission(dev_address);
    I2Cwrite(0x0);
    I2Cwrite(0x0);
    I2CendTransmission();
    
    printf("Read some bytes...\r\n");
    dev_address = 0b10100001;
  	I2CrequestFrom(dev_address, 3);
	  for (i = 0; i < 3; i++)
	  {
			data[i] = I2Cread();
		}
		printf("%i %i %i \r\n", data[0], data[1], data[2]);

    for (;;) {                  // Do forever
        c = serial_getc ();     // Get a char
        serial_putc (c);        // Echo it back
    }
}

The first issue I ran into was that it seemed to hang in the I2CendTransmission function whenever it tried to put the chip into low power. I commented out those lines and the program moved on, but I am not getting the results I expected

 

Sample output in my serial console:

Write some bytes...
Move read pointer...
Read some bytes...
0 0 0

Does anyone with kung-fu prowess have any idea what I'm doing wrong? I admit to being fairly new to actually trying to use I2C. I've tried my device address with the read/write bit set to one and zero, and it didn't seem to change the result.

 

Here is my setup; Windows 7, using commandline compilation with msp430-gcc compiler shipped with Energia.

 

I've attached my simple little project with a Makefile in case you're morbidly interested...Attached File  test.zip   21.17KB   0 downloads

 

Many thanks,

 

Keith

 

[1] - http://forum.43oh.com/topic/3216-need-help-with-i2c-using-msp430g2553/?p=33924

[2] - http://forum.43oh.com/topic/1289-tiny-printf-c-version/

[3] - http://dangerousprototypes.com/docs/3EEPROM_explorer_board#24AA_I2C_EEPROM


Viewing all articles
Browse latest Browse all 2077

Trending Articles