The power supply unit (PSU) is run through an I2C bus. This bus is used to send reset commands to the PSU board, and to receive telemetry from it.
Starting up I2C
I2C is one of three modes of the USART interface on the board. In order to set it up after a reset, the following steps must be followed:
1) Select I2C mode with SWRST = 1
2) Disable the I2C module
3) Configure the I2C module with I2CEN = 0
4) Set I2CEN via software
Example Code
//I2C test code
#include <io.h>
void waitms(int time) {
BCSCTL1=0x00; //Sets ACLK=LFXT1CLK
TACCR0=time*4; //assumes one run of clock=0.25ms
TACTL=0x01D2; //Resets timer, sources from ACLK/8, and sets to count up to TACCR0
while (!(TACTL & 1));
}
char i2csend(char *data, char address, int length ){
int i;//sets counter
P3DIR |= 0x0A;//Configure I2C pins to output, this will need to be changed to receive data
P3SEL |= 0x0A;//Sets pins to use peripheral module
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
BCSCTL2 |= SELS; //Set SMCLK to XT2 oscillator
BCSCTL2 &= ~0x06; //Set clock divider to 1
U0CTL |= SYNC + I2C; //Set USART 0 to I2C
U0CTL |= MST; //Make I2C master
U0CTL &= ~(I2CEN); //Clear I2C enable
I2CTCTL |= 0x20; //Set I2C to use SMCLK
I2CTCTL &= ~(I2CRM); //Set repeat mode to zero
I2CTCTL &= ~(I2CWORD); //Set to byte mode
I2CIE |= 0x20; //Set transmit ready interupt
I2CIE |= 0x08; //set register ready interupt
I2CPSC = 0x3; //Set prescalar multiplier to 4x
I2CSCLH = 0x8; //Set SCL high period to 8x prescalar period
I2CSCLL = 0x8; //Set SCL low period to 8x prescalar period
I2COA = 0x01; //Set own address to 1
I2CSA = address; //Set slave address
U0CTL |= I2CEN; //Renable I2C
waitms(100); //Wait for I2C to be ready
I2CTCTL |= I2CTRX; //Set transmit mode
I2CNDAT = length; //Set to transmit length bytes
for(i=0; i<length; i++){
I2CDRB = data[i]; //Gives a data byte
waitms(2);// I2C commands take ~1ms (Appendix D, I2C Bus Commands)
}
I2CTCTL |= I2CSTP; //Sets STOP condition bit
I2CTCTL |= I2CSTT; //Initiates a start condition
waitms(100); //Wait for I2C to be ready
return(I2CIE);
}
int main()
{
char data[3];
char address; // create array with sufficient length as well as address variable
int length;
char interupt;
data[0] = 0x01; // inputs 3 byte command for ttl node
data[1] = 0x00; //the adjacent checks the voltage on panel X2
data[2] = 0x03;
address = 0x41; // sets slave address
length = 3; //sets length of input
interupt = i2csend(&data[3], address, length); // passes to send function
P2DIR =255;
P2OUT = interupt; //displays interupt flags
06/07/10 : The above code has only been tested using the logic analyser. It behaves in the expected manner, dropping out after transmitting the address and failing to receive the ACK bit