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.

Cant read anything on register (Connecting problems?)



Hello guys, im having a problem on my code. Im currently using the Launchpad Tiva TM4C123 connected to a BMP085 sensor throught I2C bus trying to read the temperature.

Basically i can build it just fine and when i go to the debugger and open the register I2C_MDR_DATA, i keep getting 0xFF which means that im not connecting to the sensor. ALso created a pointer so i could get the info since the answer comes in multiple bytes. I should be getting something different from 0xFF...

Code:

#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_i2c.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "driverlib/i2c.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "utils/uartstdio.h"
#include "driverlib/uart.h"
#include "driverlib/rom.h"
#include "driverlib/fpu.h"
#include "driverlib/debug.h"

#define slave_addr 0x77
#define slave_register 0xAA

void InitI2C0()
{
//enable I2C module 0
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB))

//enable GPIO peripheral that contains I2C 0
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

ROM_GPIOPinConfigure(GPIO_PB2_I2C0SCL);
ROM_GPIOPinConfigure(GPIO_PB3_I2C0SDA);

ROM_GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
ROM_GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);

HWREG(I2C0_BASE + I2C_O_MCR) |= 0x01;

I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);
}

void I2Csend(int reg)
{
ROM_I2CMasterSlaveAddrSet(I2C0_BASE, slave_addr, false);//Here slave address configured in write mode of master
ROM_I2CMasterDataPut(I2C0_BASE,reg);//0xAA put to transmision
ROM_I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);// and sent
while(I2CMasterBusy(I2C0_BASE));

}

void I2Creceive (int *info, int reg)
{
ROM_I2CMasterSlaveAddrSet(I2C0_BASE, slave_addr, false);//Here slave address configured in write mode of master
ROM_I2CMasterDataPut(I2C0_BASE,reg);//0xAA put to transmision
ROM_I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);// and sent
while((I2CMasterBusy(I2C0_BASE)));
ROM_I2CMasterSlaveAddrSet(I2C0_BASE, slave_addr, true);//read mode
ROM_I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);// receive data comes from slave
while((I2CMasterBusy(I2C0_BASE)));
info[0] = I2CMasterDataGet(I2C0_BASE);
ROM_I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
while((I2CMasterBusy(I2C0_BASE)));
info[1] = I2CMasterDataGet(I2C0_BASE);
ROM_I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
while((I2CMasterBusy(I2C0_BASE)));
info[3] = I2CMasterDataGet(I2C0_BASE);

}

/*********************************************************************************/
int main(void)
{
int result[3] = {0,0,0};
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);

InitI2C0();
I2Csend(slave_register);
I2Creceive(result, slave_register);

}