Fixed algorithm to read 3 bytes of accelerometer data registers
Fork of COG4050_adxl355_adxl357 by
Diff: main.cpp
- Revision:
- 3:ee052fdb4331
- Parent:
- 2:14dc1ec57f3b
- Child:
- 4:23b53636b576
--- a/main.cpp Tue Aug 07 12:49:37 2018 +0000 +++ b/main.cpp Wed Aug 08 08:56:00 2018 +0000 @@ -12,81 +12,14 @@ uint8_t x; while(1) { x=accl.read_reg(accl.DEVID_AD); - printf("id = %x \r\n",x); + printf("AD id = %x \r\n",x); + x=accl.read_reg(accl.DEVID_MST); + printf("MEMS id = %x \r\n",x); + x=accl.read_reg(accl.PARTID); + printf("device id = %x \r\n",x); + x=accl.read_reg(accl.REVID); + printf("revision id = %x \r\n",x); wait(1.0); } } - - -/* -const static uint8_t _WRITE_REG_CMD = 0x0A; // write register -const static uint8_t _READ_REG_CMD = 0x0B; // read register -const static uint8_t _DUMMY_BYTE = 0xAA; - - -SPI adxl362(SPI1_MOSI, SPI1_MISO, SPI1_SCLK); -DigitalOut CS(SPI1_CS3); - -void adxl362_reset(void); -int adxl362_GetID(void); -void adxl362_write_reg(uint8_t reg, uint8_t data); -uint8_t adxl362_read_reg(uint8_t reg); - -Serial pc(USBTX, USBRX); - -int main() { - pc.baud(9600); - pc.printf("SPI ADXL362 Demo\n"); - CS = 1; - adxl362.lock(); - - //adxl362_reset(); - wait_ms(600); // we need to wait at least 500ms after ADXL362 reset - //adxl362.set_mode(ADXL362::MEASUREMENT); - uint8_t x,y,z; - while(1) { - x=adxl362_GetID(); - //y=adxl362.scany_u8(); - //z=adxl362.scanz_u8(); - //printf("x = %x y = %x z = %x\r\n",x,y,z); - printf("id = %x \r\n",x); - wait_ms(10); - } -} - -void adxl362_reset(void) -{ // format - adxl362.format(8,0); - adxl362.frequency(5e6); - - adxl362_write_reg(0x1F, 0x52); -} - -void adxl362_write_reg(uint8_t reg, uint8_t data) -{ - adxl362.format(8, 0); - CS = 0; - adxl362.write(_WRITE_REG_CMD); - adxl362.write(static_cast<uint8_t>(reg)); - adxl362.write(static_cast<uint8_t>(data)); - CS = 1; -} - -uint8_t adxl362_read_reg(uint8_t reg) -{ - uint8_t ret_val; - CS = 0; - adxl362.format(8, 0); - adxl362.write(_READ_REG_CMD); - adxl362.write(reg); - ret_val = adxl362.write(_DUMMY_BYTE); - CS = 1; - return ret_val; -} -int adxl362_GetID(void) -{ - uint8_t ret_val; - ret_val = adxl362_read_reg(0x00); - return ret_val; -}*/ \ No newline at end of file