File tree Expand file tree Collapse file tree
targets/core/atmel/atsam4s Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -133,12 +133,17 @@ namespace klib::core::atsam4s::io {
133133 // set the address we want to read from
134134 read_write_set_address<true >(address);
135135
136- // start the transaction (also set the end flag
137- // if we have less or equal than 1 byte)
138- I2c::port->CR = 0x1 | ((data.size () <= 1 && SendStop) ? (0x1 << 1 ) : 0x00 );
136+ // start the transaction
137+ I2c::port->CR = 0x1 ;
139138
140139 // read all the data
141140 for (uint32_t i = 0 ; i < data.size (); i++) {
141+ // check if this is the last byte
142+ if ((i + 1 ) >= data.size () && SendStop) {
143+ // mark the next byte is the last
144+ I2c::port->CR |= (0x1 << 1 );
145+ }
146+
142147 // wait until a nack or we have received data
143148 const uint32_t status = wait_for_status ((0x1 << 8 ) | (0x1 << 1 ));
144149
@@ -150,12 +155,6 @@ namespace klib::core::atsam4s::io {
150155
151156 // read the data into the array
152157 data[i] = I2c::port->RHR & 0xff ;
153-
154- // check if we need to send the stop condition
155- if ((data.size () > 1 ) && ((i + 1 ) >= data.size ()) && SendStop) {
156- // mark the next byte is the last
157- I2c::port->CR = (0x1 << 1 );
158- }
159158 }
160159
161160 // mask to check for
You can’t perform that action at this time.
0 commit comments