Randall Hinton

I2C baud rate and slave address problem

Discussion created by Randall Hinton on Jun 28, 2006
Latest reply on Jun 30, 2006 by Mark Hotchkiss
I am trying to communicate with a NSC200 motion controller using the RS485 on the Wytec Dragon 12 board. From the NSC200 manual the baud rate needs to be 19200. using the SCL divider equation I get 24MHZ/19200 = 1250 which doesnt match up with any numbers in the I2C block guide. So I picked 1280 w/ IBFD as $35. I chose $1 for the slave address of the NSC200. I can not get an acknowledgment from the NSC200, just a "No Ack" on my lcd.

Here is the code:
#include "c:\egnu092\include\hcs12.h"
#include "c:\egnu092\include\vectors12.h"
#include "c:\egnu092\include\delay.c"
#include "c:\egnu092\include\lcd_util_dragon12.c"

char *version = "1VE?";
char *home = "1OR";
char *NoAck = "Fail Ack";

char receive[7];
void openI2C(char ibc, char i2c_ID);
char sendCommand(char *ptr, char ID);
char readData();
void sendSlaveID (char cx);
void displayRead(void);
void displayError(void);

int main (void){
openlcd();
openI2C(0x35,0xFE); /* set I2C baud rate to 19200Hz */
//openI2C(0x00,0xA0); // input from freescale an2318sw

sendCommand(home,0x10); //move controller to home position
//sendCommand(version,0x10); /*request to receive controller version*/
//readData();
//displayRead();
while(1);
}
void openI2C(char ibc, char i2c_ID){
IBCR |= IBEN; /* enable I2C module */
IBFD = ibc; /* configure I2C clock rate */
IBAD = i2c_ID;
IBCR &= ~IBIE; /* disable I2C interrupt */
IBCR |= IBSWAI; /* disable I2C in wait mode */
}
void sendSlaveID (char cx){
while (IBSR&IBB); /* wait until I2C bus is idle */
IBCR |= TXRX+MSSL; /* generate a start condition */
IBDR = cx; //send out the slave address with R/W bit
while(!(IBSR & IBIF)); //wait for address transmission to complete
IBSR &= IBIF; /* clear IBIF flag */
}

char readData(){
char i, temp;
sendSlaveID(0x10); //generate a start condition and send NSC200*/
if (IBSR&RXAK)
displayError();
IBCR |= RSTA; /* generate a restart condition */
IBDR = 0x11; /* send ID and set R/W flag to read */
while(!(IBSR & IBIF));
IBSR = IBIF;
if (IBSR&RXAK)
displayError(); //if NSC200 did not respond, return error code
IBCR &= ~(TXRX+TXAK); /* prepare to receive and acknowledge */
temp = IBDR; /* a dummy read to trigger 9 clock pulses */
for (i = 0; i 5; i++) {
while(!(IBSR & IBIF)); /* wait for a byte to shift in */
IBSR = IBIF; /* clear the IBIF flag */
receive[i] = IBDR; /* save the current time in buffer */
} /* also initiate the next read */
while(!(IBSR & IBIF)); /* wait for the receipt of receive[5] */
IBSR = IBIF;
IBCR |= TXAK; /* not to acknowledge receive[6] */
receive[5] = IBDR; /* save receive[5] and initiate next read */
while(!(IBSR & IBIF));
IBSR = IBIF;
IBCR &= ~MSSL; /* generate stop condition */
receive[6] = IBDR;
return 0;
}

char sendCommand(char *ptr, char ID){
char i;
sendSlaveID(0x10); /* send ID to NSC200 */
if(IBSR & RXAK) /* did NSC200 acknowledge? */
displayError();

for(i = 3; i >= 0; i--) {
IBDR = *(ptr+i);
while(!(IBSR&IBIF));
IBSR = IBIF;
if(IBSR & RXAK)
displayError();
}
return 0;
}
void displayRead(void){
cmd2lcd(0x83); /* set cursor to row 1 column 3 */
puts2lcd(receive);
//cmd2lcd(0xC3); /* set cursor to row 2 column 3 */
}
void displayError(void){
cmd2lcd(0x83);
puts2lcd(NoAck);
}

Thanks
rdelljh

Outcomes