I2C 5720
-
- Posts: 8
- Joined: Thu May 27, 2010 10:00 am
I2C 5720
Hello All, am new to the net burner platform, and I am having trouble reading back data from my LM 75 temp sensor, and my LTC 2309. I am connected to the I2c buss with the SDA and SCL pins both are pulled up to 3.3 v.
On the LM75 I am trying to reads back the temperature from device register 0X00 the temperature read only register. what I get back is "Master RX: ÿÿ
Here is my code
address = 0x1001111 ;
I2CInit( address );
I2CStat =(I2CReadBuf( address,buffer,2));
if( I2CStat == I2C_OK )
{
printf("Master RX: %s\r\n", buffer);
printf( "Receive successfully\r\n" );
}
else
printf( "Failed to read due to error: %d\r\n", I2CStat);
Bob
On the LM75 I am trying to reads back the temperature from device register 0X00 the temperature read only register. what I get back is "Master RX: ÿÿ
Here is my code
address = 0x1001111 ;
I2CInit( address );
I2CStat =(I2CReadBuf( address,buffer,2));
if( I2CStat == I2C_OK )
{
printf("Master RX: %s\r\n", buffer);
printf( "Receive successfully\r\n" );
}
else
printf( "Failed to read due to error: %d\r\n", I2CStat);
Bob
Re: I2C 5720
the data that you are reading from the sensor will not be in string data.
You are using %s change it to %x for hex or %d for decimal.
printf("Master RX: %x\r\n", buffer);
You are using %s change it to %x for hex or %d for decimal.
printf("Master RX: %x\r\n", buffer);
Re: I2C 5720
As the data is split across 2 bytes, you might find the following better for checking what you are receiving.
printf("Master RX: %x, %x\r\n", buffer[0], buffer[1]);
The result from the LM75 is a 9 bit 2's complement number.
Dave...
printf("Master RX: %x, %x\r\n", buffer[0], buffer[1]);
The result from the LM75 is a 9 bit 2's complement number.
Dave...
Re: I2C 5720
Right on Dave. Totally missed that.
Re: I2C 5720
Also it looks like you are using the I2C multi-master driver since you are using an address parameter in the init call. This address will be NetBurner slave address on the bus when it is not communicating as a Master device. It probably should not be the same as your sensor address. If you omit the address and just call I2CInit(); the slave address of the NetBurner will default to 0x08.
-
- Posts: 8
- Joined: Thu May 27, 2010 10:00 am
Re: I2C 5720
Guy's, Thanks I will try out your suggestions tonight.
Bob
Bob
-
- Posts: 8
- Joined: Thu May 27, 2010 10:00 am
Re: I2C 5720
Guys,
I changed my code to the following.
I2CStat = ( I2CReadBuf(address, buffer, 3));
if( I2CStat == I2C_OK )
{
printf("Master RX: %x, %x\r\n", buffer[0], buffer[1]);
printf( "Receive successfully\r\n" );
}
else
iprintf( "Failed to read due to error: %d\r\n", I2CStat);
#endif
I now get the following.
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
Failed to read due to error: 5
which is A timeout occured while trying gain I2C bus control!
Question is there a way to set the timing of the I2C buss?
Bob
@
I changed my code to the following.
I2CStat = ( I2CReadBuf(address, buffer, 3));
if( I2CStat == I2C_OK )
{
printf("Master RX: %x, %x\r\n", buffer[0], buffer[1]);
printf( "Receive successfully\r\n" );
}
else
iprintf( "Failed to read due to error: %d\r\n", I2CStat);
#endif
I now get the following.
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
Failed to read due to error: 5
which is A timeout occured while trying gain I2C bus control!
Question is there a way to set the timing of the I2C buss?
Bob
@
Re: I2C 5720
Show us more of your code. we need to see what exactly you are doing.
Do you have "I2CInit(0x16);" 0x16 is my parameter, which may be different for you.
do you have calls like:
I2CStart( address , I2C_START_WRITE );
I2CSend( 0x00 );
I2CRestart( address , I2C_START_READ );
I2CReadBuf(address , Read_buffer, 2);
I2CStop();
Do you have "I2CInit(0x16);" 0x16 is my parameter, which may be different for you.
do you have calls like:
I2CStart( address , I2C_START_WRITE );
I2CSend( 0x00 );
I2CRestart( address , I2C_START_READ );
I2CReadBuf(address , Read_buffer, 2);
I2CStop();
-
- Posts: 8
- Joined: Thu May 27, 2010 10:00 am
Re: I2C 5720
Hello,
Here is 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>
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 address;
BYTE I2CStat;
BYTE Ascii2Byte( char* buf );
#ifndef _DEBUG
EnableSmartTraps();
#endif
#ifdef _DEBUG
InitializeNetworkGDB_and_Wait();
#endif
#ifdef _I2CMULTI_H
address = 0x1001111;
/* I2CInit( address ); */
I2CStat = ( I2CReadBuf(address, buffer, 3));
if( I2CStat == I2C_OK )
{
printf("Master RX: %x, %x\r\n", buffer[0], buffer[1]);
printf( "Receive successfully\r\n" );
}
else
iprintf( "Failed to read due to error: %d\r\n", I2CStat);
#endif
Here is 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>
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 address;
BYTE I2CStat;
BYTE Ascii2Byte( char* buf );
#ifndef _DEBUG
EnableSmartTraps();
#endif
#ifdef _DEBUG
InitializeNetworkGDB_and_Wait();
#endif
#ifdef _I2CMULTI_H
address = 0x1001111;
/* I2CInit( address ); */
I2CStat = ( I2CReadBuf(address, buffer, 3));
if( I2CStat == I2C_OK )
{
printf("Master RX: %x, %x\r\n", buffer[0], buffer[1]);
printf( "Receive successfully\r\n" );
}
else
iprintf( "Failed to read due to error: %d\r\n", I2CStat);
#endif
Re: I2C 5720
Right off, you should change the "/* I2CInit( address ); */ " to this:
I2CInit( 0x16 ); //MCF5270, MCF5234 and MCF5208
I2CInit( 0x16 ); //MCF5270, MCF5234 and MCF5208