Part Number:TM4C1294NCPDT
Tool/software: Code Composer Studio
Cannot seem to be able to get any data out to my array. I am not sure if it is my data put commands being used incorrectly or the array is being used incorrectly. In debug mode, the launchpad is changing the registers values of the slave address automatically, so im assuming the magnetometer is connected correctly to the launchpad.
I have attached my code
/*
* Mag Address: 0x1E (Write: 0x3C Read: 0x3D)
*/
// Includes
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_ints.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/i2c.h"
#include "sensorlib/i2cm_drv.h"
//Define Statements
#define Mag_read_ADDRESS 0x3D //defines lidar slave address as 0x62
#define Mag_write_ADDRESS 0x3C
#define NUM_OF_I2CBYTES 255 //defines max number of I2C bytes to be read
#define Mag_address 0x1E
//Function Prototypes
void ConfigureI2C(void);
//Global Variable Declarations
uint32_t ui32SysClkFreq; //32 bit int to store clock frequency value
uint16_t ui16alldata[2]; //16 bit data for 6 bytes of data to be read
void ConfigureI2C(void) {
//Setup I2C Peripheral I2C7
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C7);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
//while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB)) //wait for peripheral to be ready for programming
//Configure PD as I2C7SCL
//
GPIOPinConfigure(GPIO_PD0_I2C7SCL);
GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
//Configure PB3 as I2C7 specify SDA
GPIOPinConfigure(GPIO_PD1_I2C7SDA);
GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);
//Configures uC as master at I2C7, using clock frequency, (false - 100kHz), (true - 400kHz)
I2CMasterInitExpClk(I2C7_BASE, ui32SysClkFreq, true);
return;
}
int main(void) {
//Setup System Clock to 120MHz and store in variable
ui32SysClkFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ|SYSCTL_OSC_MAIN |SYSCTL_USE_PLL |SYSCTL_CFG_VCO_480), 120000000);
ConfigureI2C();
// Wait for the Peripheral to be ready for programming
//
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_I2C7));
while(1) {
int i;
//Sets the slave I2C port, slave address, true - read, false - write
I2CMasterSlaveAddrSet(I2C7_BASE, Mag_address, false);
//Writes desired register to be read to the slave
I2CMasterDataPut(I2C7_BASE, 0x3C);
I2CMasterControl(I2C7_BASE,I2C_MASTER_CMD_BURST_SEND_START);
I2CMasterDataPut(I2C7_BASE, 0x00);
I2CMasterControl(I2C7_BASE,I2C_MASTER_CMD_BURST_SEND_CONT);
I2CMasterDataPut(I2C7_BASE, 0x70);
I2CMasterControl(I2C7_BASE,I2C_MASTER_CMD_BURST_SEND_CONT);
I2CMasterDataPut(I2C7_BASE, 0x3C);
I2CMasterControl(I2C7_BASE,I2C_MASTER_CMD_BURST_SEND_CONT);
I2CMasterDataPut(I2C7_BASE, 0x01);
I2CMasterControl(I2C7_BASE,I2C_MASTER_CMD_BURST_SEND_CONT);
I2CMasterDataPut(I2C7_BASE, 0xA0);
I2CMasterControl(I2C7_BASE,I2C_MASTER_CMD_BURST_SEND_CONT);
I2CMasterDataPut(I2C7_BASE, 0x3C);
I2CMasterControl(I2C7_BASE,I2C_MASTER_CMD_BURST_SEND_CONT);
I2CMasterDataPut(I2C7_BASE, 0x02);
I2CMasterControl(I2C7_BASE,I2C_MASTER_CMD_BURST_SEND_CONT);
I2CMasterDataPut(I2C7_BASE, 0x00);
I2CMasterControl(I2C7_BASE,I2C_MASTER_CMD_BURST_SEND_CONT);
SysCtlDelay(200);
I2CMasterDataPut(I2C7_BASE, 0x3D);
I2CMasterControl(I2C7_BASE,I2C_MASTER_CMD_BURST_SEND_CONT);
I2CMasterDataPut(I2C7_BASE, 0x06);
I2CMasterControl(I2C7_BASE,I2C_MASTER_CMD_BURST_SEND_FINISH);
//Sets the slave I2C port, slave address, true - read, false - write
I2CMasterSlaveAddrSet(I2C7_BASE, Mag_address, true);
//Reads desired data from previously specified register and stores in variable
I2CMasterControl(I2C7_BASE,I2C_MASTER_CMD_BURST_RECEIVE_START);
ui16alldata[0] = I2CMasterDataGet(I2C7_BASE);
for(i=0;i<2;i++)
{
I2CMasterControl(I2C7_BASE,I2C_MASTER_CMD_BURST_RECEIVE_CONT);
ui16alldata[i+1] = I2CMasterDataGet(I2C7_BASE);
}
I2CMasterControl(I2C7_BASE,I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
ui16alldata[2] = I2CMasterDataGet(I2C7_BASE);
SysCtlDelay(2000000);
}
}
Thank you for any assistance.