Skip to main content
Renamed to better tell people what the actual question is about
Link

I2C STM8 multi- Can anybody help me rewrite this function to read two bytes?byte I2C reads

added 260 characters in body
Source Link
Chad
  • 429
  • 2
  • 8
  • 18
u8 i2c_read_register(u8 mem_address, u8 *data_read) { u8 temp = 0; u8 ack = 0; u8 device_address = (IQS_ADDR << 1); u8 polling_attempt = 0; // send address ack = i2c_send_byte(device_address); #ifdef POLLING while ((ack) && (polling_attempt < POLLING_ATTEMPTS)) { i2c_wait(); i2c_wait(); i2c_start(); ack = i2c_send_byte(device_address); polling_attempt++; } #endif if (!ack) { i2c_send_byte(mem_address); i2c_repeat_start(); device_address = (IQS_ADDR << 1) | 0x01; ack = i2c_send_byte(device_address); temp = i2c_read_byte(1); (*data_read) = temp; } return ack; } 
  • Notes In order to read two Byes I need to call the function Like This:

    i2c_read_register(DEBUGGING_EVENTS, &data_buffer[1], 2);

With (2) representing the Number of Bytes. But as the function stand it only takes two arguments not three.

u8 i2c_read_register(u8 mem_address, u8 *data_read) { u8 temp = 0; u8 ack = 0; u8 device_address = (IQS_ADDR << 1); u8 polling_attempt = 0; // send address ack = i2c_send_byte(device_address); #ifdef POLLING while ((ack) && (polling_attempt < POLLING_ATTEMPTS)) { i2c_wait(); i2c_wait(); i2c_start(); ack = i2c_send_byte(device_address); polling_attempt++; } #endif if (!ack) { i2c_send_byte(mem_address); i2c_repeat_start(); device_address = (IQS_ADDR << 1) | 0x01; ack = i2c_send_byte(device_address); temp = i2c_read_byte(1); (*data_read) = temp; } return ack; } 
u8 i2c_read_register(u8 mem_address, u8 *data_read) { u8 temp = 0; u8 ack = 0; u8 device_address = (IQS_ADDR << 1); u8 polling_attempt = 0; // send address ack = i2c_send_byte(device_address); #ifdef POLLING while ((ack) && (polling_attempt < POLLING_ATTEMPTS)) { i2c_wait(); i2c_wait(); i2c_start(); ack = i2c_send_byte(device_address); polling_attempt++; } #endif if (!ack) { i2c_send_byte(mem_address); i2c_repeat_start(); device_address = (IQS_ADDR << 1) | 0x01; ack = i2c_send_byte(device_address); temp = i2c_read_byte(1); (*data_read) = temp; } return ack; } 
  • Notes In order to read two Byes I need to call the function Like This:

    i2c_read_register(DEBUGGING_EVENTS, &data_buffer[1], 2);

With (2) representing the Number of Bytes. But as the function stand it only takes two arguments not three.

Fix code formatting
Source Link
PeterJ
  • 17.3k
  • 37
  • 58
  • 91

I2C - Can anybody Helphelp me rewrite This Functionthis function to Read Two Bytesread two bytes?

8 i2c_read_register(u8 mem_address, u8 *data_read) { u8 temp = 0; u8 ack = 0; u8 device_address = (IQS_ADDR << 1); u8 polling_attempt = 0;

u8 i2c_read_register(u8 mem_address, u8 *data_read) { u8 temp = 0; u8 ack = 0; u8 device_address = (IQS_ADDR << 1); u8 polling_attempt = 0; // send address  ack = i2c_send_byte(device_address); 

#ifdef POLLING while ((ack) && (polling_attempt < POLLING_ATTEMPTS)) { i2c_wait(); i2c_wait(); i2c_start(); ack = i2c_send_byte(device_address); polling_attempt++; } #endif if (!ack) { i2c_send_byte(mem_address); i2c_repeat_start(); device_address = (IQS_ADDR << 1) | 0x01; ack = i2c_send_byte(device_address); temp = i2c_read_byte(1); (*data_read) = temp; }

#ifdef POLLING while ((ack) && (polling_attempt < POLLING_ATTEMPTS)) { i2c_wait(); i2c_wait(); i2c_start(); ack = i2c_send_byte(device_address); polling_attempt++; } #endif if (!ack) { i2c_send_byte(mem_address); i2c_repeat_start(); device_address = (IQS_ADDR << 1) | 0x01; ack = i2c_send_byte(device_address); temp = i2c_read_byte(1); (*data_read) = temp; } return ack; } 

}

I2C - Can anybody Help me rewrite This Function to Read Two Bytes

8 i2c_read_register(u8 mem_address, u8 *data_read) { u8 temp = 0; u8 ack = 0; u8 device_address = (IQS_ADDR << 1); u8 polling_attempt = 0;

// send address ack = i2c_send_byte(device_address); 

#ifdef POLLING while ((ack) && (polling_attempt < POLLING_ATTEMPTS)) { i2c_wait(); i2c_wait(); i2c_start(); ack = i2c_send_byte(device_address); polling_attempt++; } #endif if (!ack) { i2c_send_byte(mem_address); i2c_repeat_start(); device_address = (IQS_ADDR << 1) | 0x01; ack = i2c_send_byte(device_address); temp = i2c_read_byte(1); (*data_read) = temp; }

return ack; 

}

I2C - Can anybody help me rewrite this function to read two bytes?

u8 i2c_read_register(u8 mem_address, u8 *data_read) { u8 temp = 0; u8 ack = 0; u8 device_address = (IQS_ADDR << 1); u8 polling_attempt = 0; // send address  ack = i2c_send_byte(device_address); #ifdef POLLING while ((ack) && (polling_attempt < POLLING_ATTEMPTS)) { i2c_wait(); i2c_wait(); i2c_start(); ack = i2c_send_byte(device_address); polling_attempt++; } #endif if (!ack) { i2c_send_byte(mem_address); i2c_repeat_start(); device_address = (IQS_ADDR << 1) | 0x01; ack = i2c_send_byte(device_address); temp = i2c_read_byte(1); (*data_read) = temp; } return ack; } 
Source Link
Chad
  • 429
  • 2
  • 8
  • 18
Loading