This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Part Number: MSP432P401R
Tool/software: Code Composer Studio
Hi,
I am attempting to communicate with the ADXL345 using I2C and am unable to transmit or receive data in any capacity. I have hooked up a logic analyzer and am getting the same data no matter what I am transmitting, and it is very random. I have used the example code for i2C that comes with the MSP432, and even run that on the logic analyzer where I get random unclear data.
I've attached my code below. Let me know if you have any suggestions or help I really need it!
Hi Bob,
I used the master-slave examples as an attempt to write this new code, but did not actually test it using two launchpads. However I did try and directly modify that specific code at one time to try and see data on the logic analyzer and received the same random data. I used the msp432p401x_euscib0_i2c_10 and _11 as examples and I've heard similar issues from other students that they were running into issues getting expected data on the logic analyzer. I have tested the code both on my black msp as well as my red msp. I also am currently attempting a different example code from one of the forums to see if that will work.
Let me know if you see anything that seems incorrect.
Thanks,
Noa Margalit
Hi Evan,
I have pull up resistors on the I2C lines. I am not using the black launchpad, I have tested with both. No one has had success in using the example codes including our faculty members who are experts in embedded systems. Is there any example code without interrupts? Just basic configuration and successful transmit and receive data?
I am now able to transmit the slave address but it is the only thing I can send:
Noa,
If you're only seeing the slave address, then that means you're not getting an acknowledge from the slave when sending. For these examples you need the following configuration (forgive me if some of this is obvious):
Here's what I'm using:
1. Two Red Launchpads- 1 slave, 1 Master
2. Pullups - 10kohm to 3.3v Vcc (Launchpad's 3.3v supply)
3. Grounds on LaunchPads connected to one another (avoid non-common ground issue, though this is not really a problem here)
4. Open up 2 instances of CCS 7.3 (let's call them CCS-Mstr and CCS-Slv)
- Note- you'll need to create separate workspaces for each instance and import the respective examples into them
5. Disconnect both LPs (USB) if you've not done so already
6. Start with CCS-Slave-
a. Connect the Slave LaunchPad only
b. Import & Compile msp432p401x_euscib0_i2c_11
c. connect debugger (Run-> Debug)
d. Start the slave code
7. Start the CCS- Master
a. Connect the Master LaunchPad while leaving the Slave LP connected
b. Import & Compile msp432p401x_euscib0_i2c_10
c. connect debugger (Run-> Debug)
d. Start Logic Analyzer w/ trigger on SCL HL edge
e. Start the master code
Note that, once programmed, you of course don't need the slave to be connected to the PC, but you will still need to start it before running the master.
If your procedure is different in any way from the above, let me know.
Regards,
Bob L.
Hi,
I have. I had something hooked up on my breadboard incorrectly, but I am still getting a lot of issues with the BUS being busy when it is not. I unplug the board, replug it in and the bus stays busy. I've tried reconfiguring the pins so that i have it bring the bus back to an unbusy state but it results in unexpected voltages and drops my SCL low. Here is my newer code:
#include "msp.h"
/**
* main.c
*/
void i2c_configure();
void i2c_multiple_write(uint8_t registers, uint16_t val);
void i2c_read_single_byte(uint8_t registers, uint8_t direction);
volatile uint8_t data[6];
volatile int i=0;
#define X 0
#define Y 1
#define Z 2
void main(void)
{
WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // stop watchdog timer
// if(EUSCI_B1->STATW & EUSCI_B_STATW_BBUSY){
// P1->OUT &= ~BIT5;
// P1->OUT |= BIT5;
P6->SEL1 &= ~BIT5;
P6->SEL1 &= ~BIT4;
P6->OUT |= BIT5;
P6->OUT |= BIT4;
P6->SEL0 |= BIT5;
P6->SEL0 |= BIT4;
while(1){
i2c_configure();
// i2c_multiple_write(0x2D,0x00);
// i2c_multiple_write(0x2D,0x10);
i2c_multiple_write(0x2D,0x08);
i2c_read_single_byte(0x32,X);
// for(i=0;i<20;i++);
i2c_read_single_byte(0x34,Y);
i2c_read_single_byte(0x36,Z);
// *x = (int16_t)((((int)data[1]) << 8) | data[0]);
// *y = (int16_t)((((int)data[3]) << 8) | data[2]);
// *z = (int16_t)((((int)data[5]) << 8) | data[4]);
}
}
void i2c_configure(){
// P1->SEL1 |= BIT7 | BIT6;
/*ENABLE RESET,MASTER,I2C (Mode 3), SMCLK*/
EUSCI_B1->CTLW0 = (EUSCI_B_CTLW0_SWRST |EUSCI_B_CTLW0_MST|EUSCI_B_CTLW0_MODE_3 | EUSCI_B_CTLW0_SSEL__SMCLK);
/*NO AUTOSTOP*/
EUSCI_B1->CTLW1 = EUSCI_B_CTLW1_ASTP_0;
/*SET CLOCK FOR SMCLK, 3MHZ for 100KBPS RATE*/
EUSCI_B1->BRW = 30;
/*CONFIGURE PINS 1.6 (SDA) 1.7 (SCL) (these are secondary mode pins) */
//P6->SEL0 |= BIT5 | BIT4;
// P1->SEL1 &= ~(BIT7 | BIT6);
/*
P6->SEL1 &= ~BIT5;
P6->SEL1 &= ~BIT4;
P6->OUT |= BIT5;
P6->OUT |= BIT4;
P6->SEL0 |= BIT5;
P6->SEL0 |= BIT4;
*/
/*SOFTWARE RESET DISABELE*/
EUSCI_B1->CTLW0 &= ~EUSCI_B_CTLW0_SWRST;
//EUSCI_B1->CTLW0 |= EUSCI_B_CTLW0_TXSTP;
/*SLAVE ADDRESS*/
EUSCI_B1->I2CSA = 0x53;
}
void i2c_multiple_write(uint8_t registers, uint16_t val)
{
/* Transmit mode for slave address and register read address */
EUSCI_B1->IE &= ~EUSCI_B_IE_TXIE0;
EUSCI_B1->CTLW0 |= UCTR;
EUSCI_B1->IFG &= ~EUSCI_B_IFG_TXIFG0;
while (EUSCI_B1->STATW & EUSCI_B_STATW_BBUSY);
/*START*/
EUSCI_B1->CTLW0 |= EUSCI_B_CTLW0_TXSTT;
while (!(EUSCI_B1->IFG & EUSCI_B_IFG_TXIFG0));
/*WRITE REGISTER TO TXBUF*/
EUSCI_B1 ->TXBUF = registers;
while (!(EUSCI_B1->IFG & EUSCI_B_IFG_TXIFG0));
/*WRITE VALUE TO REGISTER*/
EUSCI_B1->TXBUF = val;
/*EMPTY TX BUF? SEND STOP*/
while (!(EUSCI_B1->IFG & EUSCI_B_IFG_TXIFG0));
EUSCI_B1->CTLW0 |= EUSCI_B_CTLW0_TXSTP;
}
void i2c_read_single_byte(uint8_t registers, uint8_t direction)
{
/* Transmit mode for slave address and register read address */
EUSCI_B1->IE &= ~EUSCI_B_IE_TXIE0;
EUSCI_B1->CTLW0 |= UCTR;
EUSCI_B1->IFG &= ~EUSCI_B_IFG_TXIFG0;
while (EUSCI_B1->STATW & EUSCI_B_STATW_BBUSY);
/*START*/
EUSCI_B1->CTLW0 |= EUSCI_B_CTLW0_TXSTT;
while (!(EUSCI_B1->IFG & EUSCI_B_IFG_TXIFG0));
EUSCI_B1 ->TXBUF = registers;
while (!(EUSCI_B1->IFG & EUSCI_B_IFG_TXIFG0));
EUSCI_B1->CTLW0 |= EUSCI_B_CTLW0_TXSTP;
while (!(EUSCI_B1->IFG & EUSCI_B_IFG_TXIFG0));
/*RECEIVER MODE*/
EUSCI_B1->CTLW0 &= ~UCTR;
EUSCI_B1->CTLW0 |= EUSCI_B_CTLW0_TXSTT;
while (!(EUSCI_B1->IFG & EUSCI_B_IE_RXIE0));
if(X){
//for(i=0; i<1; i++)
//{
data[X] = (EUSCI_B1->RXBUF);
//}
}
if(Y){
data[Y] = (EUSCI_B1->RXBUF);
}
if(Z){
data[Z] = (EUSCI_B1->RXBUF);
}
EUSCI_B1->CTLW0 |= EUSCI_B_CTLW0_TXSTP;
while (!(EUSCI_B1->IFG & EUSCI_B_IFG_TXIFG0));
while (!(EUSCI_B1->IFG & EUSCI_B_IE_RXIE0));
}
It only works in collecting data some of the time, the rest of the time the line stays busy. Let me know if you have any suggestions on how to configure the pins.
**Attention** This is a public forum