Hi everybody!
I’m working in a control system for a robot, I’m testing a Header Board for ATMega128 (sku: DEV-00035) and the well know Compass Module - HMC6352.
Some months ago I was using an ATMEGA32 on a protoboard without problems, I’m doing several tests on the new ATMEGA128 in order to migrate all the program that I’ve coded.
I just read values from the sensor and display it on a LCD.
It looks fine at the beginning, but, after an aleatory amount of time, the compas sensor just freeze, sometimes get like 200 values, sometimes less than 10, it doesn’t follow an order.
I’ve changed the length of the wires, I have pull-up resistors, I’ve even bought another sensor and nothing!
This is the code that I use to read the sensor:
void read_compas(void){
uint8_t byteH, byteL,size;
uint16_t Grados;
char g[7];
i2c_start(Compas+I2C_WRITE) ; // set device address and write mode
i2c_write('A'); //Update and save a new value
_delay_ms(10);
i2c_stop();
_delay_ms(1);
i2c_start(Compas+I2C_READ); // set device address and write mode
byteH = i2c_readAck(); // read one byte form address 0
byteL = i2c_readNak(); // read one byte form address 0
i2c_stop();
Grados = byteL;
Grados += (byteH<<8);
itoa(Grados,&g[0],10);
size = strlen(g);
LCDclr();
LCDhome();
LCDstring((unsigned char *)"Grados:",7);
LCDstring((unsigned char *)g,size);
LCDstring((unsigned char *)" ",3);
_delay_ms(50);
}
By the way, I’m using the sleep mode option.
Any idea? Thanks in advance