New question on I2C communicationhttp:
Posted: Sun Aug 01, 2010 5:16 pm
Guys, I got the I2C working I can read my LTC2309 the first time. The next time i run the code it dose not function. Does any one have any thoughts.
Output first time.
Waiting 2sec to start 'A' to abort
Configured IP = 192.168.1.75
Configured Mask = 255.255.255.1
MAC Address= 00:03:f4:04:4f:28
Value of X 0
We have a 0 on the bus
Value of X 1
Value of X 2
Value of X 3
Value of X 4
Value of X 5
Value of X 6
Value of X 7
Value of X 8
We have a 8 on the bus
Value of X 9
Value of X 10
We have a A on the bus
Value of X 11
Value of X 12
Value of X 13
Value of X 14
Value of X 15
Here
Master SX: ,
Receive successfully
Master RX:0, 0,ff, ff
Receive successfully
Second Run,
Waiting 2sec to start 'A' to abort
Configured IP = 192.168.1.75
Configured Mask = 255.255.255.1
MAC Address= 00:03:f4:04:4f:28
Value of X 0
Value of X 1
Value of X 2
Value of X 3
Value of X 4
Value of X 5
Value of X 6
Value of X 7
Value of X 8
Value of X 9
Value of X 10
Value of X 11
Value of X 12
Value of X 13
Value of X 14
Value of X 15
Here
Failed to read due to error: 4
Failed to read due to error: 4
lly
My Code
#include "predef.h"
#include <stdio.h>
#include <ctype.h>
#include <startnet.h>
#include <autoupdate.h>
#include <dhcpclient.h>
#include <smarttrap.h>
#include <taskmon.h>
#include <NetworkDebug.h>
//#include "i2cmulti.h" //Used for Multi-Master I2C
#include <string.h>
#include "i2cmaster.h"
extern "C" {
void UserMain(void * pd);
}
const char * AppName="lm75";
void UserMain(void * pd) {
InitializeStack();
if (EthernetIP == 0) GetDHCPAddress();
OSChangePrio(MAIN_PRIO);
EnableAutoUpdate();
StartHTTP();
EnableTaskMonitor();
BYTE buffer[I2C_MAX_BUF_SIZE];
BYTE My_WriteBuffer[I2C_MAX_BUF_SIZE];
/* BYTE address; */
BYTE I2CStat;
BYTE Ascii2Byte( char* buf );
#ifndef _DEBUG
EnableSmartTraps();
#endif
#ifdef _DEBUG
InitializeNetworkGDB_and_Wait();
#endif
#ifdef _I2CMASTER_H
I2CInit();
for( int x =0; x<16; x++)
{
iprintf(" Value of X %d \r\n",x);
if( I2CStart( x, I2C_START_READ ) < I2C_TIMEOUT )
iprintf("We have a %X on the bus\r\n", x );
I2CStop();
}
iprintf("Here\r\n" );
/*for(int i=0;i < 1;i++){ */
*My_WriteBuffer =0x40;
I2CStat = I2CSendBuf( 8, My_WriteBuffer,1 );
if( I2CStat == I2C_OK )
{
printf("Master SX: , \r\n");
printf( "Receive successfully\r\n" );
}
else
iprintf( "Failed to read due to error: %d\r\n", I2CStat);
I2CStat = ( I2CReadBuf(0x8, buffer, 16));
I2CStop();
if( I2CStat == I2C_OK )
{
printf("Master RX:%x, %x,%x, %x\r\n", buffer[0], buffer[1],buffer[2], buffer[3]);
printf( "Receive successfully\r\n" );
}
else
iprintf( "Failed to read due to error: %d\r\n", I2CStat);
#endif
// The following function converts the first two ascii chars of a string to a single hex value
}
Output first time.
Waiting 2sec to start 'A' to abort
Configured IP = 192.168.1.75
Configured Mask = 255.255.255.1
MAC Address= 00:03:f4:04:4f:28
Value of X 0
We have a 0 on the bus
Value of X 1
Value of X 2
Value of X 3
Value of X 4
Value of X 5
Value of X 6
Value of X 7
Value of X 8
We have a 8 on the bus
Value of X 9
Value of X 10
We have a A on the bus
Value of X 11
Value of X 12
Value of X 13
Value of X 14
Value of X 15
Here
Master SX: ,
Receive successfully
Master RX:0, 0,ff, ff
Receive successfully
Second Run,
Waiting 2sec to start 'A' to abort
Configured IP = 192.168.1.75
Configured Mask = 255.255.255.1
MAC Address= 00:03:f4:04:4f:28
Value of X 0
Value of X 1
Value of X 2
Value of X 3
Value of X 4
Value of X 5
Value of X 6
Value of X 7
Value of X 8
Value of X 9
Value of X 10
Value of X 11
Value of X 12
Value of X 13
Value of X 14
Value of X 15
Here
Failed to read due to error: 4
Failed to read due to error: 4
lly
My Code
#include "predef.h"
#include <stdio.h>
#include <ctype.h>
#include <startnet.h>
#include <autoupdate.h>
#include <dhcpclient.h>
#include <smarttrap.h>
#include <taskmon.h>
#include <NetworkDebug.h>
//#include "i2cmulti.h" //Used for Multi-Master I2C
#include <string.h>
#include "i2cmaster.h"
extern "C" {
void UserMain(void * pd);
}
const char * AppName="lm75";
void UserMain(void * pd) {
InitializeStack();
if (EthernetIP == 0) GetDHCPAddress();
OSChangePrio(MAIN_PRIO);
EnableAutoUpdate();
StartHTTP();
EnableTaskMonitor();
BYTE buffer[I2C_MAX_BUF_SIZE];
BYTE My_WriteBuffer[I2C_MAX_BUF_SIZE];
/* BYTE address; */
BYTE I2CStat;
BYTE Ascii2Byte( char* buf );
#ifndef _DEBUG
EnableSmartTraps();
#endif
#ifdef _DEBUG
InitializeNetworkGDB_and_Wait();
#endif
#ifdef _I2CMASTER_H
I2CInit();
for( int x =0; x<16; x++)
{
iprintf(" Value of X %d \r\n",x);
if( I2CStart( x, I2C_START_READ ) < I2C_TIMEOUT )
iprintf("We have a %X on the bus\r\n", x );
I2CStop();
}
iprintf("Here\r\n" );
/*for(int i=0;i < 1;i++){ */
*My_WriteBuffer =0x40;
I2CStat = I2CSendBuf( 8, My_WriteBuffer,1 );
if( I2CStat == I2C_OK )
{
printf("Master SX: , \r\n");
printf( "Receive successfully\r\n" );
}
else
iprintf( "Failed to read due to error: %d\r\n", I2CStat);
I2CStat = ( I2CReadBuf(0x8, buffer, 16));
I2CStop();
if( I2CStat == I2C_OK )
{
printf("Master RX:%x, %x,%x, %x\r\n", buffer[0], buffer[1],buffer[2], buffer[3]);
printf( "Receive successfully\r\n" );
}
else
iprintf( "Failed to read due to error: %d\r\n", I2CStat);
#endif
// The following function converts the first two ascii chars of a string to a single hex value
}