SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By cidadao
#126401
Hello,

I bought a BMA180 accelerometer breakout board and Im having some problems with it.
Im using a PIC24FJ32GA002 to communicate via SPI and I can configure BMA180 and read its chip_id (0x03).

I had configured new_data_int so Im reading acceleration values after each interrupt and sending them via UART. On my PC Im using Putty serial terminal.

The values I get for X coordinate are these (just a sample):
-3259
-3255
-3258
-3261
-3260
-3250
-3253
-3254
-3261
-4
-4
-6
-7
-5
-3263
-3254
-3261
-3264
-1
-3263
-3260
-3260
-1
-3
-4
-3
-3264
-3260
The values around 3200 seems OK but I receive a lot of rubish! How can that be possible?
What sould be provoking this behaviour?

The code Im using (pretty straighforward I think):
Code: Select all
int BMA180_init(unsigned char range, unsigned char bw)
{
	char data, aux;

	if((aux=SPI_read(ID)) != 3)
		return -1;

	// set ee_w = 1
	data = SPI_read(CTRLREG0);
	data |= 0x10;
	SPI_write(CTRLREG0, data);
	
	// disable i2c
	data = SPI_read(HIGHDUR);
	data |= 0x01;
	SPI_write(HIGHDUR, data);
	
	// set new_data_int
	data = SPI_read(CTRLREG3);
	data |= 0x02;
	SPI_write(CTRLREG3, data);
	
	// Disable shadow
	data = SPI_read(0x33);
	data |= 0x01;
	SPI_write(0x33, data);
	
	// Soft reset
	SPI_write(RESET, 0xB6);
	
	delay_ms(100);

	return 0;
}
Code: Select all
void __attribute__((interrupt, no_auto_psv)) _INT2Interrupt()
{    
        char aux;

	_INT2IF = 0;

	x = SPI_read(ACCXLSB);
	aux = SPI_read(ACCXMSB);
	x |= (aux << 8);
	x = x >> 2;
	
	sprintf(buf,"%d", x);	
	U1_puts(buf);
	U1_putc('\n');
	U1_putc('\r');
}
Any sugestions?
By user245125
#135640
have you solved your problem? Because I have similar issues and maybe you already found a solution...