Hi All!
I have been attempting to interface my Stellaris Launchpad with a sparkfun BMP180 pressure/temperature sensor break out and I have hit a snag.
The necessary's all all ok (Voltage levels etc) and i have tested the breakout with a picKit Uno32 and it's working fine.
I would really like to use the Stellaris LP for the project so I started small and am attempting to read a single byte from the BMP180 via I2C.
I have read the LM4F's I2C documentation with regards to this and I saw that there is a very useful step by step guide to sending a single byte as a master around the page 971 mark.
The issue is that I cannot seem to alter the data in some of the relevant registers for I2C comms
them being the data (MDR) reg and the control (MCS) reg.
I would be very grateful if someone could throw in here !
see the following code :
#include "stdio.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
#include "driverlib/pin_map.h"
#include "driverlib/hibernate.h"
#include "driverlib/gpio.h"
#include "driverlib/uart.h"
#include "driverlib/systick.h"
#include "utils/uartstdio.h"
#include "driverlib/rom.h"
#include "driverlib/interrupt.h"
#include "driverlib/fpu.h"
#include "driverlib/i2c.h"
#include "inc/hw_ints.h"
#include "utils/ustdlib.h"
#include "string.h"
#include "stdint.h"
// Chip Header .. declares I2C3_MASTER_MCS_R etc.
#include "lm4f120h5qr.h"
/*
---Definitions
*/
#define PRES_SENSOR_ADDR 0x77 // 7-bit address
#define SEND_ADDR ((PRES_SENSOR_ADDR <<1)& 0xFE)
#define RECV_ADDR ((PRES_SENSOR_ADDR <<1)| 0x01)
//i.e. 7 addr bits and a zero for R/S bit
#define MASTER_BUSY (1u)
#define MASTER_ERR (1u<<1)
#define READ_BYTES_ERR 0x01
int main(void) {
//Set up sys clk
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 |SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ);
SysCtlDelay(10000);
//Clock gate to GPIOD
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
//Set up i2c Pin types
GPIOPinTypeI2CSCL(GPIO_PORTD_BASE,GPIO_PIN_0);
GPIOPinTypeI2C(GPIO_PORTD_BASE,GPIO_PIN_1);
GPIOPinConfigure(GPIO_PD0_I2C3SCL);
GPIOPinConfigure(GPIO_PD1_I2C3SDA);
//Enable the i2c peripheral
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);
I2CMasterInitExpClk(I2C3_MASTER_BASE,SysCtlClockGet(),false);
SysCtlDelay(10000);
int addr = 0xAA;
int byteRead =-10;
//set master up for a write
I2CMasterSlaveAddrSet(I2C3_MASTER_BASE,0x77,false);
//Put data on Data Reg
I2CMasterDataPut(I2C3_MASTER_BASE,addr);
/*So we should get 0xAA (170 decimal) on the I2C3 Data
register , but I see no chnage
*/
//Request a single send
I2CMasterControl(I2C3_MASTER_BASE,I2C_MASTER_CMD_SINGLE_SEND);
/*
Again I see no change in the memory listings for the MCS register
*/
//Wait for the Tx to finish
while(I2C3_MASTER_MCS_R & MASTER_BUSY);
//Set the Master to Read
I2CMasterSlaveAddrSet(I2C3_MASTER_BASE,0x77,true);
//We are doing a single read
I2CMasterControl(I2C3_MASTER_BASE,I2C_MASTER_CMD_SINGLE_RECEIVE);
//Wait for the Rx to finish
while(I2C3_MASTER_MCS_R & MASTER_BUSY);
if(I2C3_MASTER_MCS_R & MASTER_ERR)
{
result = (int)READ_BYTES_ERR;
}
else
{
byteRead = (int)I2CMasterDataGet(I2C3_MASTER_BASE);
}
while(1);
return 0;
}
// END OF CODE
When I run this everything compiles fine. Put as commented when I attempt to debug I do not see any changes to the I2C_MDR register after the I2CMasterDataPut() command (Reg stays at 0x00000000). So naturally I am not seeing anything returned form the temp sensor
I have tried the following:
1- Use the direct approach and setup the i2c port and regs directly using solelty the definitions in the lm4f's header file
e.g.
I2C3_MASTER_MSA_R = SEND_ADDR;
I2C3_MASTER_MDR_R = (addr & 0xFF);
I2C3_MASTER_MCS_R = 0x7;
etc.
2- A different i2c port
So I can only assume I am doing something incredibly silly here ? I can see form GPIODs regs that pull-ups and AFSEL are correct.
All help appreciated !