need help/advice on i2c
Hey everyone. My current setup is:
-An MSP430FR2355 acting as the only i2c master
-An MSP430FR2310 acting as the only i2c slave.
-I have set the slave address of the FR2310 to be 0x45
For some reason, the master sends the start bit, slave address, and read/write bit just fine, but the slave is responding with a NACK which makes me think it isn't seeing the start condition or slave address for some reason. I'll put my master and slave code below. Any help would be greatly appreciated.
Slave Code:
#include "intrinsics.h"
#include "msp430fr2310.h"
#include <msp430.h>
#define SLAVE_ADDRESS 0x45
volatile unsigned char data;
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= BIT4;
P1OUT &= ~BIT4;
P1SEL1 &= ~(BIT2 | BIT3);
P1SEL0 |= (BIT2 | BIT3);
UCB0CTLW0 |= UCSWRST;
UCB0CTLW0 &= ~UCTR;
UCB0CTLW0 &= ~UCMST;
UCB0CTLW0 |= UCMODE_3 | UCSYNC;
UCB0I2COA0 = SLAVE_ADDRESS | UCOAEN;
UCB0I2COA0 |= UCGCEN;
UCB0CTLW0 &= ~UCSWRST;
UCB0IE |= UCRXIE0;
__enable_interrupt(); // Enable global interrupts
while(1) {
P1OUT ^= BIT4;
__delay_cycles(1000);
}
}
#pragma vector=EUSCI_B0_VECTOR
__interrupt void EUSCI_B0_ISR(void)
{
}
Master Code:
#include "intrinsics.h"
#include "msp430fr2355.h"
#include <msp430.h>
void master_setup(void);
void write_to_slave(unsigned char, unsigned char);
unsigned char data = 0x42;
int i;
int main(void)
{
WDTCTL = WDTPW | WDTHOLD;
master_setup();
PM5CTL0 &= ~LOCKLPM5;
UCB0CTLW0 &= ~UCSWRST;
unsigned char slave_address = 0x45;
__enable_interrupt();
while(1)
{
write_to_slave(slave_address, data);
}
return(0);
}
void master_setup()
{
UCB0CTLW0 |= UCSWRST; //Software Reset
UCB0CTLW0 |= UCSSEL__SMCLK; //SMCLK
UCB0BRW = 10; //Set prescalar to 10
UCB0CTLW0 |= UCMODE_3; //Put into i2c mode
UCB0CTLW0 |= UCMST; //Set MSP430FR2355 as master
UCB0CTLW1 |= UCASTP_2;
UCB0TBCNT = 0x01;
P1SEL1 &= ~BIT3; //SCL setup
P1SEL0 |= BIT3;
P1SEL1 &= ~BIT2; //SDA setup
P1SEL0 |= BIT2;
}
void write_to_slave(unsigned char slave_address, unsigned char data)
{
UCB0I2CSA = slave_address;
UCB0CTLW0 |= UCTR;
UCB0IE |= UCTXIE0;
UCB0CTLW0 |= UCTXSTT;
for(i = 0; i < 100; i++)
{
}
UCB0IE &= ~UCTXIE0;
UCB0CTLW0 &= ~UCTR;
}
#pragma vector=EUSCI_B0_VECTOR
__interrupt void EUSCI_B0_I2C_ISR(void)
{
UCB0TXBUF = data;
}