Hi,
i am trying to port my code from the black launchpad into the new red one.
So far the code works but the i2c part doenst.
First thing i write into a 8bit register a 16bit value and this is my function:
bool writeI2C_16_2(uint8_t ui8Addr, uint8_t ui8Reg, uint16_t Data, uint8_t ui8ByteCount)
{
/* Todo: Put a delay */
/* Wait until ready */
//while (MAP_I2C_isBusBusy(EUSCI_B3_BASE)); <--------------------------------------------------first it got stuck here so i coment it out
/* Disable I2C module to make changes */
MAP_I2C_disableModule(EUSCI_B3_BASE);
/* Setup the number of bytes to receive */
i2cConfig2.autoSTOPGeneration = EUSCI_B_I2C_NO_AUTO_STOP;
g_ui32ByteCount_2 = ui8ByteCount;
burstMode_2 = true;
MAP_I2C_initMaster(EUSCI_B3_BASE, (const eUSCI_I2C_MasterConfig *)&i2cConfig2);
/* Load device slave address */
MAP_I2C_setSlaveAddress(EUSCI_B3_BASE, ui8Addr);
/* Enable I2C Module to start operations */
MAP_I2C_enableModule(EUSCI_B3_BASE);
/* Enable master STOP and NACK interrupts */
MAP_I2C_enableInterrupt(EUSCI_B3_BASE, EUSCI_B_I2C_STOP_INTERRUPT +EUSCI_B_I2C_NAK_INTERRUPT);
/* Set our local state to Busy */
ui8Status_2 = eUSCI_BUSY_2;
/* Send start bit and register */
MAP_I2C_masterSendMultiByteStart(EUSCI_B3_BASE,ui8Reg);
/* Enable master interrupt for the remaining data */
MAP_Interrupt_enableInterrupt(INT_EUSCIB3);
/* NOTE: If the number of bytes to receive = 1, then as target register is being shifted
* out during the write phase, UCBxTBCNT will be counted and will trigger STOP bit prematurely
* If count is > 1, wait for the next TXBUF empty interrupt (just after reg value has been
* shifted out
*/
while(ui8Status_2 == eUSCI_BUSY_2)
{
if(MAP_I2C_getInterruptStatus(EUSCI_B3_BASE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0))
{
ui8Status_2 = eUSCI_IDLE_2;
}
}
ui8Status_2 = eUSCI_BUSY_2;
/* Turn off TX and generate RE-Start */
//MAP_I2C_masterReceiveStart(EUSCI_B0_BASE);
//I2C_masterSendMultiByteFinish(EUSCI_B3_BASE, Data);
/* Send the MSB to SENSOR */
MAP_I2C_masterSendMultiByteNext(EUSCI_B3_BASE,
(unsigned char)(Data>>8));
MAP_I2C_masterSendMultiByteFinish(EUSCI_B3_BASE,
(unsigned char)(Data&0xFF));
/* Enable RX interrupt */
MAP_I2C_enableInterrupt(EUSCI_B3_BASE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0);
// Wait for all data be received
while(ui8Status_2 == eUSCI_BUSY_2)
{
__no_operation();<------------------------------------------------------------------------------------------------------------Then it get stuck here
}
/* Disable interrupts */
MAP_I2C_disableInterrupt(EUSCI_B3_BASE, EUSCI_B_I2C_STOP_INTERRUPT +EUSCI_B_I2C_NAK_INTERRUPT + EUSCI_B_I2C_TRANSMIT_INTERRUPT0);
MAP_Interrupt_disableInterrupt(INT_EUSCIB3);
if(ui8Status_2 == eUSCI_NACK_2)
{
return(false);
}
else
{
return(true);
}
}
So the i2c interrupt should handle it and change the status, but non interrupt occurs. Here is my interrupt service routine:
oid EUSCIB3_IRQHandler(void)
{
uint_fast16_t status;
status = MAP_I2C_getEnabledInterruptStatus(EUSCI_B3_BASE);
MAP_I2C_clearInterruptFlag(EUSCI_B3_BASE, status);
if (status & EUSCI_B_I2C_NAK_INTERRUPT)
{
/* Generate STOP when slave NACKS */
MAP_I2C_masterSendMultiByteStop(EUSCI_B3_BASE);
/* Clear any pending TX interrupts */
MAP_I2C_clearInterruptFlag(EUSCI_B3_BASE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0);
/* Set our local state to NACK received */
ui8Status_2 = eUSCI_NACK_2;
}
if (status & EUSCI_B_I2C_START_INTERRUPT)
{
/* Change our local state */
ui8Status_2 = eUSCI_START_2;
}
if (status & EUSCI_B_I2C_STOP_INTERRUPT)
{
/* Change our local state */
ui8Status_2 = eUSCI_STOP_2;
}
if (status & EUSCI_B_I2C_RECEIVE_INTERRUPT0)
{
/* RX data */
*pData_2++ = MAP_I2C_masterReceiveMultiByteNext(EUSCI_B3_BASE);
ui8DummyRead_2= MAP_I2C_masterReceiveMultiByteNext(EUSCI_B3_BASE);
//*pData_2++= MAP_I2C_masterReceiveMultiByteNext(EUSCI_B3_BASE);
if (burstMode_2)
{
g_ui32ByteCount_2--;
if (g_ui32ByteCount_2 == 1)
{
burstMode_2 = false;
/* Generate STOP */
MAP_I2C_masterSendMultiByteStop(EUSCI_B3_BASE);
}
}
}
if (status & EUSCI_B_I2C_TRANSMIT_INTERRUPT0)
{
/* Send the next data */
MAP_I2C_masterSendMultiByteNext(EUSCI_B3_BASE, *pData_2++);
}
//#ifdef USE_LPM
// MAP_Interrupt_disableSleepOnIsrExit();
//#endif
}
I have measured both line SCL and SDA and it this functions didnt send out anything:
/* Send the MSB to SENSOR */
MAP_I2C_masterSendMultiByteNext(EUSCI_B3_BASE,
(unsigned char)(Data>>8));
MAP_I2C_masterSendMultiByteFinish(EUSCI_B3_BASE,
(unsigned char)(Data&0xFF));
So thats why no interrupt occured. Why are this functions not working?
On the black launchpad they worked, all this code was working on the black lp.
Any idea?