September 25, 2013

MSP430 Controlling an SI570...

So from the previous post, I have a simple I2C library that I can use to try on things other than the 24XX EEPROM. And from this post I have a simple little breakout for the SI570. So I decided to put peanut butter in my chocolate (or is it my chocolate in my peanut butter) and see if I can control the SI570 with the I2C library.

Using a control word found in sample code from here to set the si570 to 14.200MHz, I ripped up some code real quick to do it and was astonished and pumped when I saw the frequency meter on my DMM jump to 14.20 MHz upon reflashing my launchpad.

Here is the code that worked when I compiled it:
#include <msp430.h>
#include "serial.h"
#include "i2c.h"

void msprintf(char *format, ...);

void main(void)
{
    char c;
    char dev_address = 0xAA;
    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);
    
    msprintf("serial is working...\r\n");
    char err;

    char i2cWriteBuf[] = {0, 0, 0, 0, 0, 0};
    int j;

    // Hard reset of frequency to 14.2 MHz
    i2cWriteBuf[0]=0xA9 ; 
    i2cWriteBuf[1]=0xC2; 
    i2cWriteBuf[2]=0xA8 ; 
    i2cWriteBuf[3]=0x7C ; 
    i2cWriteBuf[4]=0x5D ; 
    i2cWriteBuf[5]=0x39; 
    kpprintf("14.2 MHz\r\n");

    msprintf("init i2c...\r\n");
    i2c_init();
    __delay_cycles(20000);

      
    //Freeze DCO
    msprintf("Freeze DCO...\r\n");
    u8 buf;
    buf = 0b00010000;
    i2c_tx(1, dev_address, &buf, 0, 137); 

    msprintf("Write buffer...\r\n");
    for (i = 0; i < 6 ; ++i) 
    { 
      i2c_tx(1, dev_address, i2cWriteBuf, 0, i+8); 
    }
    //Unfreeze DCO  
    msprintf("Unfreeze DCO...\r\n");
    buf = 0;
    i2c_tx(1, dev_address, &buf, 0, 137); 
    
    msprintf("Read input from serial...\r\n");
    for (;;) {                  // Do forever
      c = serial_getc ();     // Get a char
      serial_putc (c);        // Echo it back
    }
}

So this was strictly a prototype to see if I could at least get the SI570 controlled with a brute force large frequency jump. Next step is to actually create a little library that I can use to control the si570. I found a great integer based source code example that allowed doing the 38-bit math required in some of the calculations here. Adapting it to pass in a structure (so multiple si570s could be controlled), I hope to get this wrapped up pretty soon.

http://www.henriquegravina.net/pu3ike/si570/

September 15, 2013

Launchpad, I2C, EEPROM = WINNING!

I've got tiger blood. Or something. Who else uses bad internet memes years after they're even remotely funny?

So this post is to document the travails I encountered in trying to get I2C working with the MSP430 Launchpad and a simple EEPROM memory chip, wired up my brutally hacked version of the dangerousprototype's 3EEPROM board.

Let's cover the background; I have a TI MSP430 Launchpad that I want to eventually be the controller for my SI570 break-out board, shown here [1]. My first thought was to use Energia, as it has the nice Wire library for I2C interactions, as well as a serial writing functionality for debugging. I naively tried adapting some code snippets I found on the googletubes to see if I could get the frequency to change, but to no avail.

The next step, then, was to simplify. Let's make sure that my I2C stuff was actually doing what I thought it was doing. So when I put on an I2C sniffer, it showed nada, zip, zilch, nuthin, zero. Well crap, apparently I don't know how to use the Wire library.

To test whether or not I could do I2C, I decided to try and do something ridiculously easy, and stumbled upon the 3EEPROM board of dangerousprototypes.com [2], complete with command sets to test it out. I procured the 25xx and 24xx SPI and I2C PROM chips and built a simple little protoboard circuit for testing purposes. Useless and requisite photo here:


All I wanted to do was write a couple of bytes to the 24xx chip and read 'em back. So began the long and painful journey....along the way I found a nice useful serial debug library (based upon work by oPossum of 43oh) [3], and got the workings of a simple skeleton makefile/project to work.

While the 0101E0009 release of Energia didn't seem to work for me, the latest release, 0101E0010 did the trick. But I wanted to see it work outside of Energia, as I really don't like the IDE provided with it. I may eventually try to get an external makefile to work (like this here [4]), but for now I'll continue with what I have working here. I eventually found an I2C library that worked for me (located here in the 43Oh forums by member V0JT4 [5]). I needed to add a simple little function that must have been an intrinsic with the compiler he was using, the _swap_bytes function.

As can be seen from the wiring picture below, I'm using the Gabotronics Xprotolab [6] as a protocol sniffer, powered from the 5V tap near the USB connection of the Launchpad. The 24XX chip has an I2C address of  0x50 hex, and examing the blurry picture you can see the bytes of the phrase HELLO WORLD being sent back and forth from it. Use asciitable.com to help with the translation of hex into ASCII values if you're really bored.



Anyway, I put the code up on github [7]; almost none of it is original code from me. Thanks to the awesome forum at 43oh for basically doing all of the heavy lifting for me!

[1] - http://underwaterwhistler.blogspot.com/2013/08/si570-breakout-fun.html
[2] - http://dangerousprototypes.com/docs/3EEPROM_explorer_board#24AA_I2C_EEPROM
[3] - http://forum.43oh.com/topic/1289-tiny-printf-c-version/
[4] - https://github.com/elpaso/energia-makefile
[5] - http://forum.43oh.com/topic/1772-universal-ripple-control-receiver/
[6] - http://www.gabotronics.com/development-boards/xmega-xprotolab.htm
[7] - https://github.com/kpimmel/msp430_i2cEEPROM