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.
Tool/software: Code Composer Studio
Good day,
I am going through the MSP430Ware driverlib examples to understand how I2C works with MSP430F5529 launchpad. I have attached 27kOhm pull up resistors to pins 3.0 and 3.1 (UCB0SCL and UCB0SDA). However when I run the code shown below:
/* --COPYRIGHT--,BSD * Copyright (c) 2016, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --/COPYRIGHT--*/ #include "driverlib.h" //***************************************************************************** //! This example shows how to configure the I2C module as a master for //! single byte transmission in interrupt mode. The address of the slave //! module that the master is communicating with also set in this example. //! //! This example uses the following peripherals and I/O signals. You must //! review these and change as needed for your own board: //! - I2C peripheral //! - GPIO Port peripheral (for I2C pins) //! - SCL2 //! - SDA //! //! This example uses the following interrupt handlers. To use this example //! in your own application you must add these interrupt handlers to your //! vector table. //! - USCI_B0_VECTOR. //! // //***************************************************************************** //***************************************************************************** // //Set the address for slave module. This is a 7-bit address sent in the //following format: //[A6:A5:A4:A3:A2:A1:A0:RS] // //A zero in the "RS" position of the first byte means that the master //transmits (sends) data to the selected slave, and a one in this position //means that the master receives data from the slave. // //***************************************************************************** #define SLAVE_ADDRESS 0x62 //LiDAR Lite v3 slave address uint8_t transmitData; void main(void) { //Stop WDT WDT_A_hold(WDT_A_BASE); //Assign I2C pins to USCI_B0 GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P3, GPIO_PIN0 + GPIO_PIN1 ); //Initialize transmit data packet transmitData = 0x00; //Initialize Master USCI_B_I2C_initMasterParam param = {0}; param.selectClockSource = USCI_B_I2C_CLOCKSOURCE_SMCLK; param.i2cClk = UCS_getSMCLK(); param.dataRate = USCI_B_I2C_SET_DATA_RATE_400KBPS; USCI_B_I2C_initMaster(USCI_B0_BASE, ¶m); //Specify slave address USCI_B_I2C_setSlaveAddress(USCI_B0_BASE, SLAVE_ADDRESS ); //Set in transmit mode USCI_B_I2C_setMode(USCI_B0_BASE, USCI_B_I2C_TRANSMIT_MODE ); //Enable I2C Module to start operations USCI_B_I2C_enable(USCI_B0_BASE); //Enable TX interrupt USCI_B_I2C_clearInterrupt(USCI_B0_BASE, USCI_B_I2C_TRANSMIT_INTERRUPT ); USCI_B_I2C_enableInterrupt(USCI_B0_BASE, USCI_B_I2C_TRANSMIT_INTERRUPT ); while(1) { //Send single byte data. USCI_B_I2C_masterSendSingleByte(USCI_B0_BASE, transmitData ); //Delay until transmission completes while(USCI_B_I2C_isBusBusy(USCI_B0_BASE)) { ; } //Delay between each transaction __delay_cycles(50); //Increment transmit data counter } } //****************************************************************************** // //This is the USCI_B0 interrupt vector service routine. // //****************************************************************************** #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=USCI_B0_VECTOR __interrupt #elif defined(__GNUC__) __attribute__((interrupt(USCI_B0_VECTOR))) #endif void USCI_B0_ISR(void) { switch(__even_in_range(UCB0IV,12)) { //Vector 12: Transmit buffer empty - TXIF case USCI_I2C_UCTXIFG: { __no_operation(); break; } default: break; } }
It then hangs in the following code in usci_b_i2c.c:
//Poll for transmit interrupt flag. while(!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG)) { ; }
I have read other threads but they do not help me with my issue. When I check the pins on oscilloscope they remain permanently high at 3.3v. They never go low. I have tried the other examples and the same issue comes up in that the code will hang in usci_b_i2c.c
The only thing I changed in the code above is the slave address from 0x48 to 0x62 as that is the slave address for the LiDAR Lite v3 sensor which has internal 3kOhm resistors. Any assistance with being able to get the readings from the sensor will be very much appreciated or even getting the I2C just to send out a simple start byte.
Hi Ryan,
From my basic understanding, a level shifter is not necessary. I measured the output voltage of the SCL and SDA lines from the Lidar Lite v3 and they both output 3.3 V which is the same as the SCL and SDA pins on the MSP430F5529LP board.
I tried communicating with the sensor without the additional pull-up resistors but again, the code hangs in that section I highlighted in my original post and I have no idea why. It simply will not transmit even a start byte. It gets stuck when UCTXIFG is set to 1 indicating the TX buffer is empty and ready to receive more data but instead it endlessly loops. There is no output whatsoever from the microcontroller. As I said earlier, the SDA and SCL lines remain permanently high at 3.3 V, never going low to indicate a start bit has been sent through.
As for coding it in C, I have no proper knowledge of the register level editing required. I am a student with limited time as I complete the project I am currently working on, the driverslib library is thus essential for my needs
Others have managed to get the example code to work, I just want to know why my microcontroller will not even send out a start bit let alone a whole byte when using the example code.
I have looked at others implementations and I do not see what is wrong as I am using the exact same code as them with pull-up resistors connected from P3.0 and P3.1 to 3V3 pin which is Vcc.
Are you at least able to tell me if my pin setup is correct? The original example uses pins 1 and 2 on Port 3 (P3.1 and P3.2). I changed it to Port 3.0 and 3.1 as that is the SDA and SCL pins. Is that perhaps an error on my part? Here is the MSP430F5529LP pinout to illustrate:
Should I be using pins 4.1 and 4.2 instead? Truly and honestly all I want is to get past the hanging in the loop as I indicated earlier.
I will try put together the example as intended when I am in the lab tomorrow.
Again, my issue is that the board will not even output a start byte with address. It gets stuck in that loop. That is all I want solved for now, why does it get stuck there? It doesn't output anything on the SDA or SCL pin.
**Attention** This is a public forum