Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

[LM3S6965] I2C Error - Reads 255

$
0
0

Hello all..

I am having a problem when trying to read data from my PCA9629 Fm+ I2C-bus stepper motor controller. I am using the Stellaris LM3S6965.

When i try and read the values on any of the 39 Registers i always get 255 back (1111 1111). ( I am guessing this is the "error" value that basic says that it times out when waiting for a response ???? )

Anyone that can find any errors in my code??? Slave address is 0x40, and register is 0x00 to 0x26 (you can read them all) 

Code :
______________________________________________________________________________________________________________
 //Set the Clock to run 8MHz

SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_8MHZ);

//Enables the I2C0

SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

// Enable Port B of GPIO
// SDA 0 Bit 3 Output
// SCL 0 Bit 2 Output

GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);// Port B 2 y 3

// Initializes the I2C Master block with clock

I2CMasterInitExpClk( I2C0_MASTER_BASE, SysCtlClockGet(), false);
//True=400Kbps
//False=100Kbps

//Delay for a moment.

SysCtlDelay(80000);

//Enables the Display

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

RIT128x96x4Init(3500000);

// Enable processor interrupts.

IntMasterEnable(); //runs the users commands.

// Data stores the value returned from the I2C
int Data;

// Buffer0 used in the Itoa
char buffer0[32] = "";

// This Command contains a start condition.
// false=write / true=read
I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, 0x22, false);

while(I2CMasterBusy(I2C0_MASTER_BASE));

// The first bit defines if it uses auto increment or not.
// REGISTER:******, R/W:r, HEX:40
I2CMasterDataPut(I2C0_MASTER_BASE,0x40);

// Starts sending the data.
I2CMasterControl(I2C0_MASTER_BASE,I2C_MASTER_CMD_SINGLE_SEND);

// Wait for I2C to finish.
while(I2CMasterBusy(I2C0_MASTER_BASE));

// This Command contains a start condition.
// false=write / true=read
I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, 0x22, true);

// Starts receiving the data
I2CMasterControl(I2C0_MASTER_BASE,I2C_MASTER_CMD_SINGLE_RECEIVE);

// Puts the received byte data into the int Data
Data = I2CMasterDataGet(I2C0_MASTER_BASE);

// Wait for I2C to finish.
while(I2CMasterBusy(I2C0_MASTER_BASE));

// A short delay.
SysCtlDelay(80000);

// Basic Itoa (moves stored value from data to buffer0)

itoa(Data,buffer0,2);

// prints on the screen the value stores in buffer0

RIT128x96x4StringDraw(buffer0, 50, 50, 15);


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>