Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to read a sequence of bytes through I2C?
    text
    copied!<p>I want to read a sequence of bytes from my accelerometer. I can't get it work. When I read byte by byte all is ok, but when I try to read sequence I can't get a true values. </p> <pre><code> void ADXL_ReadSeq(uint8_t StartAddr,signed char *data) { // StartAddr |= (1&lt;&lt;7); // while(I2C_GetFlagStatus(I2CG, I2C_FLAG_BUSY)); // While the bus is busy I2C_GenerateSTART(I2CG, ENABLE); // Send START condition while(!I2C_CheckEvent(I2CG, I2C_EVENT_MASTER_MODE_SELECT)); // Test on EV5 and clear it I2C_Send7bitAddress(I2CG, DEV_ADDR&lt;&lt; 1, I2C_Direction_Transmitter); // Send address for write (SAD+W) while(!I2C_CheckEvent(I2CG, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); // Test on EV6 and clear it I2C_SendData(I2CG,ADXL_R| ADXL_MB|StartAddr ); // Send the internal address to read from: MSB of the address first while(!I2C_CheckEvent(I2CG, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); // Test on EV8 and clear it I2C_GenerateSTART(I2CG, ENABLE); // Send STRAT condition a second time while(!I2C_CheckEvent(I2CG, I2C_EVENT_MASTER_MODE_SELECT)); // Test on EV5 and clear it I2C_Send7bitAddress(I2CG, DEV_ADDR&lt;&lt; 1, I2C_Direction_Receiver); // Send address for read while(!I2C_CheckEvent(I2CG,I2C_EVENT_MASTER_BYTE_RECEIVED)); // Test on EV6 and clear it int num=6; while (num) { if(num==1) { I2C_AcknowledgeConfig(I2C1, DISABLE); /* ЧоєуТ»О»єуТЄ№Ш±ХУ¦ґрµД */ I2C_GenerateSTOP(I2C1, ENABLE); /* ·ўЛННЈЦ№О» */ } while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED)); /* EV7 */ *data = I2C_ReceiveData(I2C1); data++; /* Decrement the read bytes counter */ num--; } /* ФЩґОФКРнУ¦ґрДЈКЅ */ I2C_AcknowledgeConfig(I2C1, ENABLE); } </code></pre> <p>What I'm doing wrong? I convert this function from other function which uses SPI <a href="http://code.google.com/p/flyless/source/browse/trunk/FLYLess/src/hal/adxl345.c" rel="nofollow">http://code.google.com/p/flyless/source/browse/trunk/FLYLess/src/hal/adxl345.c</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload