Hi,
I am trying to interface BMP180 module to my TM4C123GXL microcontroller kit. Here is my code:
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "tm4c123gh6pm.h"
#include "wait.h"
// Addresses as per the Bosch datasheet
#define BMP180_ADDR_W 0xEE
#define BMP180_ADDR_R 0xEF
// I2C Master Control/Status Register (Read Only)
#define I2C1_MCS_BUSY 0x01
#define I2C1_MCS_ERR 0x02
// I2C Master Control/Status Register (Write Only)
#define I2C1_MCS_ACK 0x08
#define I2C1_MCS_NACK 0x00
#define I2C1_MCS_STOP 0x04
#define I2C1_MCS_START 0x02
#define I2C1_MCS_RUN 0x01
void initHw()
{
// Configure HW to work with 16 MHz XTAL, PLL enabled, system clock of 40 MHz
SYSCTL_RCC_R = SYSCTL_RCC_XTAL_16MHZ | SYSCTL_RCC_OSCSRC_MAIN | SYSCTL_RCC_USESYSDIV | (4 << SYSCTL_RCC_SYSDIV_S);
// Set GPIO ports to use APB (not needed since default configuration -- for clarity)
// Note UART on port A must use APB
SYSCTL_GPIOHBCTL_R = 0;
// Enable GPIO port B and E peripherals
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOA;
// Configure the I2C module 1 for BMP180 sensor
SYSCTL_RCGCI2C_R |= SYSCTL_RCGCI2C_R1;
waitMicrosecond(1000);
GPIO_PORTA_AFSEL_R |= 0xC0;
GPIO_PORTA_DEN_R |= 0xC0;
GPIO_PORTA_ODR_R |= 0x80;
GPIO_PORTA_PUR_R |= 0x40;
GPIO_PORTA_PCTL_R |= ((3<<28)|(3<<24));
I2C1_MCR_R |= 0x10;
I2C1_MTPR_R = (19<<0);
}
void slaveAddress(uint16_t address)
{
I2C1_MSA_R = (address);
}
int main(void)
{
initHw();
slaveAddress(BMP180_ADDR_W);
I2C1_MDR_R = 0xEE;
I2C1_MCS_R |= (I2C1_MCS_START|I2C1_MCS_RUN|I2C1_MCS_STOP);
while(1);
}
i didn't use any external pull-up resistors. Activated the internal pull ups as shown in the code.
On debugging, the I2CMSA register gets updated with the value of the slave address of BMP180 i.e. 0xEE but, the I2CMDR register value doesn't change. Why is this happening??
Regards,
Rohan