void mma_get_average( uint8_t power_of_two, int16_t * x, int16_t * y, int16_t * z )
{
    int16_t accu_x = 0;
    int16_t accu_y = 0;
    int16_t accu_z = 0;
    uint8_t i;
    for ( i = 0; i < ( 1 << power_of_two ); ++i ) {
        mma_wait_until_ready();
        accu_x += mma_read10( MMA_XOUT10 );
        accu_y += mma_read10( MMA_YOUT10 );
        accu_z += mma_read10( MMA_ZOUT10 );
    }
    *x = accu_x >> power_of_two;
    *y = accu_y >> power_of_two;
    *z = accu_z >> power_of_two;
}
// 1 <= power_of_two <= 6
void mma_get_average( uint8_t power_of_two, int16_t * x, int16_t * y, int16_t * z )
{
    int16_t accu_x = 0;
    int16_t accu_y = 0;
    int16_t accu_z = 0;
    uint8_t i;
    for ( i = 0; i < ( 1 << power_of_two ); ++i ) {
        mma_wait_until_ready();
    	ACL_CS=0;
    	spi_rw( 0x00 );//setup read
        accu_x += mma_read10( MMA_XOUT10 );
        accu_y += mma_read10( MMA_YOUT10 );
        accu_z += mma_read10( MMA_ZOUT10 );
		ACL_CS=1;
    }
    *x = ( accu_x + ( 1 << ( power_of_two - 1 ) ) ) >> power_of_two;
    *y = ( accu_y + ( 1 << ( power_of_two - 1 ) ) ) >> power_of_two;
    *z = ( accu_z + ( 1 << ( power_of_two - 1 ) ) ) >> power_of_two;
}