MCPcopy Create free account
hub / github.com/SmingHub/Sming / twi_writeTo

Function twi_writeTo

Sming/Core/si2c.cpp:186–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

184}
185
186uint8_t twi_writeTo(uint8_t address, const uint8_t* buf, size_t len, bool sendStop)
187{
188 if(!twi_write_start()) {
189 return 4; //line busy
190 }
191 if(!twi_write_byte(((address << 1) | 0) & 0xFF)) {
192 if(sendStop) {
193 twi_write_stop();
194 }
195 return 2; //received NACK on transmit of address
196 }
197 for(unsigned i = 0; i < len; i++) {
198 if(!twi_write_byte(buf[i])) {
199 if(sendStop) {
200 twi_write_stop();
201 }
202 return 3; //received NACK on transmit of data
203 }
204 }
205 if(sendStop) {
206 twi_write_stop();
207 }
208 for(unsigned i = 0; SDA_READ() == 0 && i++ < 10;) {
209 SCL_LOW();
210 twi_delay(twi_dcount);
211 SCL_HIGH();
212 twi_delay(twi_dcount);
213 }
214 return 0;
215}
216
217uint8_t twi_readFrom(uint8_t address, uint8_t* buf, size_t len, bool sendStop)
218{

Callers 1

endTransmissionMethod · 0.70

Calls 4

twi_write_startFunction · 0.85
twi_write_byteFunction · 0.85
twi_write_stopFunction · 0.85
twi_delayFunction · 0.85

Tested by

no test coverage detected