Skip to content

Commit 55ede66

Browse files
committed
atsam4s moved marking end of transaction to cleanup code
1 parent 4a3efd7 commit 55ede66

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

targets/core/atmel/atsam4s/i2c.hpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)