Hello everyone, I am intended to read acceleration signals from adxl345 through SPI. I am using Tinynode platform (which does not have any I2C output port). Therefore I have to use SPI.
When I read the DevID of the adxl345, I get 0xF2 instead of 0xE5. So what I get is 11110010 and what I expect is 11100101 . When I google, I find people (who are not using TinyOS) also have similar problem that can be see here: http://e2e.ti.com/support/microcontrollers/msp430/f/166/t/52871. I must admit I can not understand the code there. My question number ONE is how to fix the problem above. I am calling the SPI using SpiPacket.send() function. I am referring and modifying the code of ADE7753 chip for my application. I have another question on the code below (which belongs to ADE7753P): async event void SpiPacket.sendDone(uint8_t* txBuf, uint8_t* rxBuf, uint16_t len, error_t spi_error ) { uint32_t val; error_t error = spi_error; call SPIFRM.set(); // CS HIGH atomic { switch (mState) { case STATE_GETREG: mState = STATE_IDLE; // repack switch (len) { case 2: val = rxBuf[1]; break; case 3: val = ((uint32_t)rxBuf[1])<<8 | rxBuf[2]; break; case 4: val = ((uint32_t)rxBuf[1])<<16 | ((uint32_t)rxBuf[2])<<8 | rxBuf[3]; break; default: val = 0xF0F0F0F0; break; } signal ADE7753.getRegDone(error, (txBuf[0] & 0x7F), val, len); break; The question number TWO is why rxB[0] is not read? I test the code above I found out that I need to read rxBuf[0] as the lower byte of the X-axis data. My third question is how to cover 2s complement to uint16_t data, so that I can send through wireless and display on PC screen using Oscilloscope app . My best attempt is as shown below: async event void SpiPacket.sendDone(uint8_t* txBuf, uint8_t* rxBuf, uint16_t len, error_t spi_error ) { int16_t sigval; //sign value uint16_t val; //unsign value error_t error = spi_error; call SPIFRM.set(); // CS HIGH atomic { switch (mState) { case STATE_GETREG: mState = STATE_IDLE; // repack switch (len) { case 2: val = rxBuf[0]; break; case 3: sigval = ((uint16_t)rxBuf[1])<<8 | rxBuf[0]; // val = ((uint16_t)rxBuf[2])<<8 | rxBuf[1];// I m not sure if I should use this Val=(uint16_t)(sigval+32768); //level shift the sig value. break; default: val = 0xF0F0F0F0; break; } signal ADE7753.getRegDone(error, (txBuf[0] & 0x7F), val, len); break; But, when I rotates the accel, the upper half the sin wave is at the bottom of the graph and the lower half sine wave is at the top of the graph. Please help. Regards, Wong Kiing Ing DISCLAIMER: The information contained in this e-mail and any attachments is confidential and may be legally privileged. If the recipient of this message is not the intended addressee, be advised that you have received this message in error and that legal professional privilege is not waived and you are requested to re-send to the sender and promptly delete this e-mail and any attachments. If you are not the intended addressee, you are strictly prohibited from using, reproducing, disclosing or distributing the information contained in this e-mail and any attached files. Curtin University, Sarawak Malaysia ("Curtin Sarawak") advises that this e-mail and any attached files should be scanned to detect viruses. Curtin Sarawak does not represent or warrant that this e-mail including any attachments is free from computer viruses or defects. Curtin Sarawak shall not be responsible for any loss or damage incurred in their use.
_______________________________________________ Tinyos-help mailing list [email protected] https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
