@@ -210,10 +210,33 @@ void free_bus(uint8_t pos) {
210210int machine_hw_i2c_transfer (mp_obj_base_t * self_in ,uint16_t addr ,size_t n ,mp_machine_i2c_buf_t * bufs ,unsignedint flags ) {
211211machine_hw_i2c_obj_t * self = MP_OBJ_TO_PTR (self_in );
212212i2c_cmd_handle_t cmd = i2c_cmd_link_create ();
213+
214+ int data_len = 0 ;
215+
216+ if (flags & MP_MACHINE_I2C_FLAG_WRITE1 ) {
217+ i2c_master_start (cmd );
218+ i2c_master_write_byte (cmd ,addr <<1 , true);
219+ i2c_master_write (cmd ,bufs -> buf ,bufs -> len , true);
220+ data_len += bufs -> len ;
221+ -- n ;
222+ ++ bufs ;
223+ }
224+
213225i2c_master_start (cmd );
214226i2c_master_write_byte (cmd ,addr <<1 | (flags & MP_MACHINE_I2C_FLAG_READ ), true);
215227
216- int data_len = 0 ;
228+ // printf("I2C transfer: addr=%02X, n=%u", addr, n);
229+ // if (flags & MP_MACHINE_I2C_FLAG_READ) {
230+ // printf(", read");
231+ // }
232+ // else if (flags & MP_MACHINE_I2C_FLAG_STOP) {
233+ // printf(", stop");
234+ // }
235+ // else {
236+ // printf(", write");
237+ // }
238+ // printf("\n");
239+
217240for (;n -- ;++ bufs ) {
218241if (flags & MP_MACHINE_I2C_FLAG_READ ) {
219242i2c_master_read (cmd ,bufs -> buf ,bufs -> len ,n == 0 ?I2C_MASTER_LAST_NACK :I2C_MASTER_ACK );