Quantcast
Channel: MSP low-power microcontrollers
Viewing all articles
Browse latest Browse all 62309

Forum Post: RE: MSP432 I2C Multibytes Receive using Driverlib

$
0
0
Hi Michael, This is how I do it "readI2C": bool readI2C(uint8_t ui8Addr, uint8_t ui8Reg, uint8_t *Data, uint8_t ui8ByteCount) { /* Todo: Put a delay */ /* Wait until ready */ while (MAP_I2C_isBusBusy(EUSCI_B1_BASE)); /* Assign Data to local Pointer */ pData = Data; /* Disable I2C module to make changes */ MAP_I2C_disableModule(EUSCI_B1_MODULE); /* Setup the number of bytes to receive */ i2cConfig.byteCounterThreshold = ui8ByteCount; i2cConfig.autoSTOPGeneration = EUSCI_B_I2C_SEND_STOP_AUTOMATICALLY_ON_BYTECOUNT_THRESHOLD; MAP_I2C_initMaster(EUSCI_B1_MODULE, (const eUSCI_I2C_MasterConfig *)&i2cConfig); /* Load device slave address */ MAP_I2C_setSlaveAddress(EUSCI_B1_MODULE, ui8Addr); /* Enable I2C Module to start operations */ MAP_I2C_enableModule(EUSCI_B1_MODULE); /* Enable master STOP and NACK interrupts */ MAP_I2C_enableInterrupt(EUSCI_B1_MODULE, EUSCI_B_I2C_STOP_INTERRUPT + EUSCI_B_I2C_NAK_INTERRUPT); /* Set our local state to Busy */ ui8Status = eUSCI_BUSY; /* Send start bit and register */ MAP_I2C_masterSendMultiByteStart(EUSCI_B1_MODULE,ui8Reg); /* Enable master interrupt for the remaining data */ MAP_Interrupt_enableInterrupt(INT_EUSCIB1); /* 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 == eUSCI_BUSY) { if(MAP_I2C_getInterruptStatus(EUSCI_B1_MODULE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0)) { ui8Status = eUSCI_IDLE; } } ui8Status = eUSCI_BUSY; /* Turn off TX and generate RE-Start */ MAP_I2C_masterReceiveStart(EUSCI_B1_MODULE); /* Enable RX interrupt */ MAP_I2C_enableInterrupt(EUSCI_B1_MODULE, EUSCI_B_I2C_RECEIVE_INTERRUPT0); /* Wait for all data be received */ while(ui8Status == eUSCI_BUSY) { #ifdef USE_LPM MAP_PCM_gotoLPM0(); #else __no_operation(); #endif } /* Disable interrupts */ MAP_I2C_disableInterrupt(EUSCI_B1_MODULE, EUSCI_B_I2C_STOP_INTERRUPT + EUSCI_B_I2C_NAK_INTERRUPT + EUSCI_B_I2C_RECEIVE_INTERRUPT0); MAP_Interrupt_disableInterrupt(INT_EUSCIB1); if(ui8Status == eUSCI_NACK) { return(false); } else { return(true); } } For your reference, you want to take a look at this project: dev.ti.com/.../ And these two files: dev.ti.com/.../ dev.ti.com/.../ Hopefully this helps. David

Viewing all articles
Browse latest Browse all 62309

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>