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'm trying to connect ds1307 with msp432p401r launchpad (red) using i2c protocol, but no luck.
msp432 is sending the data but not receiving ( transmit-->poll and receive--> interrupt ).
I'm using the code from the driverlib "i2c_master_rw_repeated_start-master_code"
Could you please provide me with some kind of sample code for interfacing RTC ds1307 with msp432p401r launchpad (red) using the i2c protocol.
Thanks.
Hi Chris,
I was also trying to interface ds1307 with msp432p401r.
Above reference helped me to send multiple byte data.
But still ds1307 is not interfacing with msp432p401r.
Please go through my code.
I'm also attaching the pic of SCL and SDA Waveforms.
Thanks.
Pic :- Yellow waveform is SCL, Green waveform is SDA.
CODE:
/* DriverLib Includes */
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
/* Standard Includes */
#include <stdint.h>
#include <stdbool.h>
/* Slave Address for I2C Slave */
#define SLAVE_ADDRESS 0xD0
/* Statics */
//uint8_t TXData[]= {0xD0,0x07,0x10}; // Pointer to TX data
uint8_t TXData[]= {0xD1,0x04}; // Pointer to TX data
static uint8_t TXByteCtr;
static volatile uint32_t xferIndex;
static volatile bool stopSent;
static uint8_t RXData[10];
static uint32_t numOfRecBytes;
int flag,flag1,i;
uint8_t SlaveFlag = 0;
/* I2C Master Configuration Parameter */
const eUSCI_I2C_MasterConfig i2cConfig =
{
EUSCI_B_I2C_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
3000000, // SMCLK = 3MHz
EUSCI_B_I2C_SET_DATA_RATE_100KBPS, // Desired I2C Clock of 400khz
0, // No byte counter threshold
EUSCI_B_I2C_NO_AUTO_STOP // No Autostop
};
int main(void)
{
volatile uint32_t ii;
/* Disabling the Watchdog */
MAP_WDT_A_holdTimer();
/* Select Port 1 for I2C - Set Pin 6, 7 to input Primary Module Function,( UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL)*/
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,GPIO_PIN6 + GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION);
/* Initializing I2C Master to SMCLK at 400kbs with no autostop */
MAP_I2C_initMaster(EUSCI_B0_BASE, &i2cConfig);
/* Specify slave address */
MAP_I2C_setSlaveAddress(EUSCI_B0_BASE, SLAVE_ADDRESS);
/* Set Master in transmit mode */
MAP_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_MODE);
/* Enable I2C Module to start operations */
MAP_I2C_enableModule(EUSCI_B0_BASE);
/* Enable and clear the interrupt flag */
MAP_I2C_clearInterruptFlag(EUSCI_B0_BASE,EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT);
/* Enable master transmit interrupt */
MAP_I2C_enableInterrupt(EUSCI_B0_BASE,EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT);
MAP_Interrupt_enableInterrupt(INT_EUSCIB0);
while (1)
{
/* Delay between Transmissions */
for (ii = 0; ii < 10000; ii++);
/* Load Byte Counter */
TXByteCtr = 1;
// /* Making sure the last transaction has been completely sent out */
// while (MAP_I2C_masterIsStopSent(EUSCI_B0_BASE) == EUSCI_B_I2C_SENDING_STOP);
//
// /* Sending the initial start condition */
// MAP_I2C_masterSendMultiByteStart(EUSCI_B0_BASE, TXData[SlaveFlag]);
while (EUSCI_B0->CTLW0 & EUSCI_B_CTLW0_TXSTP); // Ensure stop condition got sent
EUSCI_B0->CTLW0 |= EUSCI_B_CTLW0_TR | EUSCI_B_CTLW0_TXSTT; // I2C TX, start condition
MAP_Interrupt_enableSleepOnIsrExit();
MAP_PCM_gotoLPM0InterruptSafe();
}
}
/*******************************************************************************
* The USCIAB0TX_ISR is structured such that it can be used to transmit any
* number of bytes by pre-loading TXByteCtr with the byte count. Also, TXData
* points to the next byte to transmit.
******************************************************************************/
void EUSCIB0_IRQHandler(void)
{
uint_fast16_t status;
status = MAP_I2C_getEnabledInterruptStatus(EUSCI_B0_BASE);
MAP_I2C_clearInterruptFlag(EUSCI_B0_BASE, status);
if (status & EUSCI_B_I2C_NAK_INTERRUPT)
{
MAP_I2C_masterSendStart(EUSCI_B0_BASE);
}
if (status & EUSCI_B_I2C_TRANSMIT_INTERRUPT0)
{
/* Check the byte counter */
if (TXByteCtr) //4=0,3=1;2=2,1=3
{
/* Send the next data and decrement the byte counter */
MAP_I2C_masterSendMultiByteNext(EUSCI_B0_BASE,TXData[SlaveFlag]);
TXByteCtr--;
SlaveFlag++;
if (SlaveFlag>3) // Roll over slave address
{
SlaveFlag =0;
}
}
else
{
flag++;
MAP_I2C_masterSendMultiByteStop(EUSCI_B0_BASE);
MAP_Interrupt_disableSleepOnIsrExit();
MAP_I2C_disableInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0);
MAP_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_MODE);
xferIndex = 0;
MAP_I2C_masterReceiveStart(EUSCI_B0_BASE);
MAP_I2C_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_INTERRUPT0);
}
}
if (status & EUSCI_B_I2C_RECEIVE_INTERRUPT0)
{
if(xferIndex == 0)
{
RXData[xferIndex++] = MAP_I2C_masterReceiveMultiByteNext(EUSCI_B0_BASE);
numOfRecBytes = RXData[0];
}
else if (xferIndex == (numOfRecBytes - 2))
{
MAP_I2C_masterReceiveMultiByteStop(EUSCI_B0_BASE);
RXData[xferIndex++] = MAP_I2C_masterReceiveMultiByteNext(EUSCI_B0_BASE);
}
else if (xferIndex == (numOfRecBytes - 1))
{
RXData[xferIndex++] = MAP_I2C_masterReceiveMultiByteNext(EUSCI_B0_BASE);
MAP_I2C_disableInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_INTERRUPT0);
MAP_I2C_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_STOP_INTERRUPT);
MAP_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_MODE);
xferIndex = 0;
stopSent = true;
MAP_Interrupt_disableSleepOnIsrExit();
}
else
{
RXData[xferIndex++] = MAP_I2C_masterReceiveMultiByteNext(EUSCI_B0_BASE);
}
}
}
**Attention** This is a public forum