Tool/software: TI C/C++ Compiler
hello everyone i'm trying to get the HMC5883L to work , but my code gets stuck checking if bus is busy at the first occurrence of while(ROM_I2CMasterBusy(I2C1_BASE)); , am i messing something ,please help
#define TARGET_IS_BLIZZARD_RB1
#define PART_TM4C123GH6PM
#include <stdint.h> // ift
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/i2c.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/pin_map.h"
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_i2c.h"
void send_start(int a,int b,int c){
ROM_I2CMasterSlaveAddrSet(I2C1_BASE,0x1E, false);
ROM_I2CMasterDataPut(I2C1_BASE, a);
ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_START);
while(ROM_I2CMasterBusy(I2C1_BASE));
ROM_I2CMasterDataPut(I2C1_BASE, b);
ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
while(ROM_I2CMasterBusy(I2C1_BASE));
ROM_I2CMasterDataPut(I2C1_BASE, c);
ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
while(ROM_I2CMasterBusy(I2C1_BASE));
}
void send_start2(int a,int b){
ROM_I2CMasterSlaveAddrSet(I2C1_BASE,0x1E, false);
ROM_I2CMasterDataPut(I2C1_BASE, a);
ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_START);
while(ROM_I2CMasterBusy(I2C1_BASE));
ROM_I2CMasterDataPut(I2C1_BASE, b);
ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
while(ROM_I2CMasterBusy(I2C1_BASE));
}
void ReadByteArray(int *arr,int cnt);
int data[6]={1,2,3,4,5,6};
int main(void)
{
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
ROM_GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);
ROM_GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);
ROM_I2CMasterInitExpClk(I2C1_BASE, SysCtlClockGet(), false);
//initialization process for “continuous-measurement mode (HMC5883L) Page 18
//(8-average, 15 Hz default, normal measurement)
send_start(0x3C,0x00,0x70);
//(Gain=5, or any other desired gain)
send_start(0x3C,0x01,0xA0);
//(Continuous-measurement mode)
send_start(0x3C,0x02,0x00);
ROM_SysCtlDelay(5500000); // writing time
while(1){
send_start2(0x3D,0x03);// 1
ReadByteArray(data,1);
}
}
void ReadByteArray(int *arr,int cnt){
int i=1;
ROM_I2CMasterSlaveAddrSet(I2C1_BASE, 0x1E, false);
ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
while(ROM_I2CMasterBusy(I2C1_BASE));
arr[0] = ROM_I2CMasterDataGet(I2C1_BASE); //test
for (i=1;i<cnt;i++)
{
ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
//
while(ROM_I2CMasterBusy(I2C1_BASE));
arr[i] = ROM_I2CMasterDataGet(I2C1_BASE); //Receive
}
ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
//
while(ROM_I2CMasterBusy(I2C1_BASE));
}