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.
So, I was able to fix a first issue on the I2C, and what I want to obtain as a first step is to see in a while loop
the transmission of a dummy byte on my logic analyser. My current code is the following
#include "driverlib.h" #include <stdio.h> #include <string.h> /* Global Defines */ #define CS_MCLK_DESIRED_FREQUENCY_IN_KHZ 16000 /**< Target frequency for MCLK in kHz */ #define CS_MCLK_FLLREF_RATIO 488 /**< MCLK/FLLRef Ratio */ int main(void) { volatile uint32_t i; uint8_t transmitData; WDT_A_hold(WDT_A_BASE); GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P3, GPIO_PIN2 | GPIO_PIN6); GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P3, GPIO_PIN2 + GPIO_PIN6, GPIO_PRIMARY_MODULE_FUNCTION ); /* * Disable the GPIO power-on default high-impedance mode to activate * previously configured port settings */ PMM_unlockLPM5(); //Initialize transmit data packet transmitData = 0x01; //Initialize Master EUSCI_B_I2C_initMasterParam param = {0}; param.selectClockSource = EUSCI_B_I2C_CLOCKSOURCE_SMCLK; param.i2cClk = CS_getSMCLK(); param.dataRate = EUSCI_B_I2C_SET_DATA_RATE_400KBPS; param.byteCounterThreshold = 1; param.autoSTOPGeneration = EUSCI_B_I2C_NO_AUTO_STOP; EUSCI_B_I2C_initMaster(EUSCI_B1_BASE, ¶m); //Specify slave address EUSCI_B_I2C_setSlaveAddress(EUSCI_B1_BASE, 0x48 ); //Set in transmit mode EUSCI_B_I2C_setMode(EUSCI_B1_BASE, EUSCI_B_I2C_TRANSMIT_MODE ); //Enable I2C Module to start operations EUSCI_B_I2C_enable(EUSCI_B1_BASE); while(1) { EUSCI_B_I2C_masterSendSingleByte(EUSCI_B1_BASE, 0xAA //Send MSB of the address first ); for(i=100000; i>0; i--); } }
would normally expect to see on the logic analyser a sequence of transmission attempts to address 0x48, all ending with a NAK since the peripheral is not connected.
What I get is a single transmission as in the screen capture below
and then the SCL line stays low.
By debugging the code, I found out that the program gets stuck in the eusci_b_i2c.c file, at line 192 at the following instruction of function EUSCI_B_I2C_masterSendSingleByte()
//Poll for transmit interrupt flag. while (!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG)) ;
Is this happening because no peripheral is connected? How to solve this? thanks in advance!
EUSCI_B_I2C_masterSendSingleByte doesn't check for NACK, so it will hang in that case. If you think a NACK is possible/likely, use EUSCI_B_I2C_masterSendSingleByteWithTimeout instead (I think you need to send a Stop on a failure).
Are you fairly sure your I2C address is correct? Keep in mind that the R/W bit is Not part of the address. The only "mainstream" 0x48 device I see in the Adafruit list is TMP102. Is that what you're using?
Hello Bruce,
thanks for your reply, this solved my issue. In fact, for the moment I am just studying how the I2C works on the driverlib, so I did not connect any device to the I2C pins. 0x48 is just the value I found on the TI example and I didn't change it.
Your solution works perfectly, now I got NACKs (as expected) but the MSP does not hang.
Thanks a lot!
**Attention** This is a public forum