- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'm using CY8CKIT-044, I want to get data from MPU9250. I have already make code (based on github) in arduino Mega and the program running nicely, I got data from accelerometer, gyroscope and magnetometer very well.
I want to convert code from arduino to PSoC creator, but I can't get even raw data, so i think my code isn't right, first i want to check if my 'i2c read/write functions' for the MPU9250 is right.
Hope can find the solution from this community.
note : first row is arduino code and second row is converted code.
#1
uint8_t readByte(uint8_t address, uint8_t subAddress)
{
uint8_t data; // `data` will store the register data
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
Wire.requestFrom(address, (size_t) 1); // Read one byte from slave register address
data = Wire.read(); // Fill Rx buffer with result
return data; // Return data read from slave register
}
|
uint8_t i2c_readByte(uint8_t address, uint8_t reg) |
void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t * dest)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
uint8_t i = 0;
Wire.requestFrom(address, (size_t) count); // Read bytes from slave register address
while (Wire.available()) {
dest[i++] = Wire.read();
} // Put read results in the Rx buffer
}
|
void i2c_readBytes(uint8_t address, uint8_t reg, uint8_t byteCount, uint8_t * destinationBuffer) { I2C_MPU9250_I2CMasterSendStart(address, 0, I2C_TimeOut); I2C_MPU9250_I2CMasterWriteByte(reg, I2C_TimeOut); I2C_MPU9250_I2CMasterSendRestart(address, 1, I2C_TimeOut); while (byteCount--) { if (!byteCount) { /* Last byte */ I2C_MPU9250_I2CMasterReadByte(0,destinationBuffer++,I2C_TimeOut); } else { I2C_MPU9250_I2CMasterReadByte(1,destinationBuffer++,I2C_TimeOut); } } I2C_MPU9250_I2CMasterSendStop(I2C_TimeOut); } |
void writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.write(data); // Put data in Tx buffer
Wire.endTransmission(); // Send the Tx buffer
}
|
void i2c_writeByte(uint8_t address, uint8_t reg, uint8_t data) { I2C_MPU9250_I2CMasterSendStart(address, 0, I2C_TimeOut); I2C_MPU9250_I2CMasterWriteByte(reg, I2C_TimeOut); I2C_MPU9250_I2CMasterWriteByte(data, I2C_TimeOut); I2C_MPU9250_I2CMasterSendStop(I2C_TimeOut); } |
Solved! Go to Solution.
- Labels:
-
PSoC Creator & Designer Software
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Copy of https://community.cypress.com/t5/PSoC-Creator-Designer-Software/convert-code-from-arduino/td-p/28506... , will tracked there.