i2c send 2 byte addres - Raspberry Pi Forums


hi community,
putting soft in c ++ need read , write block of data dsp.
these routines read , write in arduino:
//——————————————————————————————————————————————————————————————————————————//
void dsp_write_register_array(uint8_t dspaddress, uint16_t address, byte a, byte b, byte c, byte d)
{
uint8_t addr[] = {address>>8, address&0xff};
uint8_t buf[] = {a,b,c,d};

wire.begintransmission(dspaddress); // begin write
wire.write(addr, 2);
wire.write(buf, 4);
wire.endtransmission(true); // write out data i2c , stop transmitting

delay(10);
}


//——————————————————————————————————————————————————————————————————————————//
void dsp_read_register(uint8_t dspaddress, uint16_t address, uint8_t *data)
{
uint8_t index = 0;
uint8_t addr[] = {address>>8, address&0xff};

wire.begintransmission(dspaddress); // begin write
wire.write(addr, 2); // send internal address want read
wire.endtransmission(false); // write out data i2c don't send stop condition on i2c bus

wire.requestfrom(dspaddress, 4); // request n bytes slave device

while(wire.available()) // slave may send less requested
{
data[index] = wire.read(); // receive byte character
index++;
delay(2);
}
}
can see, write need send 2 bytes command (uint16_t) , array (uint8_t) of 4 data.
use function:
i2c_smbus_write_i2c_block_data(fd, command, size, data);
sends first data of 1 byte , array, solve sending first byte in parameter command , 4 + 1 array data first data second command byte.
functional use, problem comes when have read, when can send data of 1 byte.
tried use function i2c_smbus_write_byte_data(fd, command, data); send first byte , i2c_smbus_read_i2c_block_data(fd, command, size, data); feature opens , closes communication , second function again sends request open communication, not working.
i'm working c ++ libraries colleague made communicate i2c system libraries:
https://github.com/kashimastro/ofxgpio
intention update library in order have more options after solving this.
thank sharing!
greetings!!



raspberrypi



Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code