85 uint8_t *data = readData;
86 uint32_t count = nrBytes;
88 if ((i2cREG1->STR & (uint32_t)I2C_BUSBUSY) == 0u) {
90 i2cREG1->MDR &= ~((uint32_t)I2C_STOP_COND);
91 i2cREG1->MDR &= ~((uint32_t)I2C_START_COND);
92 i2cREG1->MDR &= ~((uint32_t)I2C_REPEATMODE);
93 i2cREG1->STR |= (uint32_t)I2C_TX_INT;
94 i2cREG1->STR |= (uint32_t)I2C_RX_INT;
96 i2cSetMode(i2cREG1, (uint32_t)I2C_MASTER);
97 i2cSetDirection(i2cREG1, (uint32_t)I2C_TRANSMITTER);
98 i2cSetSlaveAdd(i2cREG1, slaveAddress);
99 i2cSetCount(i2cREG1, 1u);
100 i2cSetStart(i2cREG1);
101 i2cREG1->DXR = (uint32_t)readAddress;
105 while (((i2cREG1->STR & (uint32_t)I2C_TX_INT) == 0u) && (timeout > 0u)) {
106 if ((i2cREG1->STR & (uint32_t)I2C_NACK) != 0u) {
115 i2cREG1->MDR |= (uint32_t)I2C_REPEATMODE;
119 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
125 if ((i2cREG1->STR & (uint32_t)I2C_NACK) == 0u) {
126 i2cSetMode(i2cREG1, (uint32_t)I2C_MASTER);
127 i2cSetDirection(i2cREG1, (uint32_t)I2C_RECEIVER);
128 i2cSetCount(i2cREG1, nrBytes);
129 i2cSetStart(i2cREG1);
135 while (((i2cREG1->STR & (uint32_t)I2C_RX_INT) == 0u) && (timeout > 0u)) {
136 if ((i2cREG1->STR & (uint32_t)I2C_NACK_INT) != 0u) {
142 if ((nack ==
true) || (timeout == 0u)) {
145 *data = ((uint8)i2cREG1->DRR);
149 if ((nack ==
true) || (timeout == 0u)) {
151 i2cREG1->MDR |= (uint32_t)I2C_REPEATMODE;
155 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
162 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
168 i2cClearSCD(i2cREG1);
190 uint8_t *data = readData;
191 uint32_t count = nrBytes;
193 if ((i2cREG1->STR & (uint32_t)I2C_BUSBUSY) == 0u) {
195 i2cREG1->MDR &= ~((uint32_t)I2C_STOP_COND);
196 i2cREG1->MDR &= ~((uint32_t)I2C_START_COND);
197 i2cREG1->MDR &= ~((uint32_t)I2C_REPEATMODE);
198 i2cREG1->STR |= (uint32_t)I2C_TX_INT;
199 i2cREG1->STR |= (uint32_t)I2C_RX_INT;
200 i2cREG1->STR |= (uint32_t)I2C_TX_INT;
201 i2cREG1->STR |= (uint32_t)I2C_RX_INT;
203 i2cSetMode(i2cREG1, (uint32_t)I2C_MASTER);
204 i2cSetDirection(i2cREG1, (uint32_t)I2C_RECEIVER);
205 i2cSetSlaveAdd(i2cREG1, slaveAddress);
206 i2cSetCount(i2cREG1, nrBytes);
207 i2cSetStart(i2cREG1);
213 while (((i2cREG1->STR & (uint32_t)I2C_RX_INT) == 0u) && (timeout > 0u)) {
214 if ((i2cREG1->STR & (uint32_t)I2C_NACK_INT) != 0u) {
220 if ((nack ==
true) || (timeout == 0u)) {
223 *data = ((uint8)i2cREG1->DRR);
227 if ((nack ==
true) || (timeout == 0u)) {
229 i2cREG1->MDR |= (uint32_t)I2C_REPEATMODE;
233 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
240 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
246 i2cClearSCD(i2cREG1);
263 uint8_t *data = writeData;
264 uint32_t count = nrBytes;
266 if ((i2cREG1->STR & (uint32_t)I2C_BUSBUSY) == 0u) {
268 i2cREG1->MDR &= ~((uint32_t)I2C_STOP_COND);
269 i2cREG1->MDR &= ~((uint32_t)I2C_START_COND);
270 i2cREG1->MDR &= ~((uint32_t)I2C_REPEATMODE);
271 i2cREG1->STR |= (uint32_t)I2C_TX_INT;
272 i2cREG1->STR |= (uint32_t)I2C_RX_INT;
274 i2cSetMode(i2cREG1, (uint32_t)I2C_MASTER);
275 i2cSetDirection(i2cREG1, (uint32_t)I2C_TRANSMITTER);
276 i2cSetSlaveAdd(i2cREG1, slaveAddress);
278 i2cSetCount(i2cREG1, nrBytes + 1u);
279 i2cSetStart(i2cREG1);
282 i2cREG1->DXR = (uint32_t)writeAddress;
285 while (((i2cREG1->STR & (uint32_t)I2C_TX_INT) == 0u) && (timeout > 0u)) {
286 if ((i2cREG1->STR & (uint32_t)I2C_NACK) != 0u) {
294 i2cREG1->MDR |= (uint32_t)I2C_REPEATMODE;
298 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
304 if ((i2cREG1->STR & (uint32_t)I2C_NACK) == 0u) {
309 while (((i2cREG1->STR & (uint32_t)I2C_TX_INT) == 0u) && (timeout > 0u)) {
310 if ((i2cREG1->STR & (uint32_t)I2C_NACK) != 0u) {
316 if ((nack ==
true) || (timeout == 0u)) {
319 i2cREG1->DXR = (uint32_t)*data;
323 if ((nack ==
true) || (timeout == 0u)) {
324 i2cREG1->MDR |= (uint32_t)I2C_REPEATMODE;
328 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
335 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
341 i2cClearSCD(i2cREG1);
363 uint8_t *data = writeData;
364 uint32_t count = nrBytes;
366 if ((i2cREG1->STR & (uint32_t)I2C_BUSBUSY) == 0u) {
368 i2cREG1->MDR &= ~((uint32_t)I2C_STOP_COND);
369 i2cREG1->MDR &= ~((uint32_t)I2C_START_COND);
370 i2cREG1->MDR &= ~((uint32_t)I2C_REPEATMODE);
371 i2cREG1->STR |= (uint32_t)I2C_TX_INT;
372 i2cREG1->STR |= (uint32_t)I2C_RX_INT;
374 i2cSetMode(i2cREG1, (uint32_t)I2C_MASTER);
375 i2cSetDirection(i2cREG1, (uint32_t)I2C_TRANSMITTER);
376 i2cSetSlaveAdd(i2cREG1, slaveAddress);
378 i2cSetCount(i2cREG1, nrBytes);
379 i2cSetStart(i2cREG1);
382 if ((i2cREG1->STR & (uint32_t)I2C_NACK) == 0u) {
387 while (((i2cREG1->STR & (uint32_t)I2C_TX_INT) == 0u) && (timeout > 0u)) {
388 if ((i2cREG1->STR & (uint32_t)I2C_NACK) != 0u) {
394 if ((nack ==
true) || (timeout == 0u)) {
397 i2cREG1->DXR = (uint32_t)*data;
401 if ((nack ==
true) || (timeout == 0u)) {
402 i2cREG1->MDR |= (uint32_t)I2C_REPEATMODE;
406 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
413 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
419 i2cClearSCD(i2cREG1);
440 if ((i2cREG1->STR & (uint32_t)I2C_BUSBUSY) == 0u) {
460 i2cSetMode(i2cREG1, (uint32_t)I2C_MASTER);
461 i2cSetDirection(i2cREG1, (uint32_t)I2C_TRANSMITTER);
462 i2cSetSlaveAdd(i2cREG1, slaveAddress);
463 i2cSetCount(i2cREG1, 1u);
464 i2cSetStart(i2cREG1);
465 i2cSendByte(i2cREG1, readAddress);
468 while ((i2cREG1->STR & (uint32_t)I2C_TX_INT) == 0u) {
469 if ((i2cREG1->STR & (uint32_t)I2C_NACK) != 0u) {
474 if ((i2cREG1->STR & (uint32_t)I2C_NACK) == 0u) {
475 i2cSetDirection(i2cREG1, (uint32_t)I2C_RECEIVER);
476 i2cSetCount(i2cREG1, nrBytes);
477 i2cSetMode(i2cREG1, (uint32_t)I2C_MASTER);
479 i2cSetStart(i2cREG1);
481 i2cREG1->STR |= (uint32_t)I2C_NACK;
482 i2cREG1->STR |= (uint32_t)I2C_TX_INT;
487 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
491 i2cClearSCD(i2cREG1);
502 uint32_t slaveAddress,
503 uint8_t writeAddress,
505 uint8_t *writeData) {
511 if ((i2cREG1->STR & (uint32_t)I2C_BUSBUSY) == 0u) {
530 i2cSetMode(i2cREG1, (uint32_t)I2C_MASTER);
531 i2cSetDirection(i2cREG1, (uint32_t)I2C_TRANSMITTER);
532 i2cSetSlaveAdd(i2cREG1, slaveAddress);
534 i2cSetCount(i2cREG1, nrBytes + 1u);
535 i2cSendByte(i2cREG1, writeAddress);
537 i2cSetStart(i2cREG1);
540 while ((i2cREG1->STR & (uint32_t)I2C_TX_INT) == 0u) {
541 if ((i2cREG1->STR & (uint32_t)I2C_NACK) != 0u) {
546 if ((i2cREG1->STR & (uint32_t)I2C_NACK) != 0u) {
547 i2cREG1->STR |= (uint32_t)I2C_NACK;
548 i2cREG1->STR |= (uint32_t)I2C_TX_INT;
552 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
556 i2cClearSCD(i2cREG1);
557 i2cREG1->STR &= ~(uint32_t)I2C_REPEATMODE;
569 i2cREG1->MDR &= ~((uint32_t)I2C_STOP_COND);
570 i2cREG1->MDR &= ~((uint32_t)I2C_START_COND);
571 i2cREG1->MDR &= ~((uint32_t)I2C_REPEATMODE);
572 i2cREG1->STR |= (uint32_t)I2C_TX_INT;
573 i2cREG1->STR |= (uint32_t)I2C_RX_INT;
575 i2cREG1->MDR |= (uint32_t)I2C_REPEATMODE;
576 i2cSetMode(i2cREG1, (uint32_t)I2C_MASTER);
577 i2cSetDirection(i2cREG1, (uint32_t)I2C_TRANSMITTER);
580 while (i2cIsStopDetected(i2cREG1) == 0u) {
583 i2cREG1->MDR &= ~(uint32_t)I2C_REPEATMODE;
584 i2cClearSCD(i2cREG1);
588 #ifdef UNITY_UNIT_TEST
Headers for the driver for the DMA module.
#define DMA_CHANNEL_I2C_TX
#define DMA_CHANNEL_I2C_RX
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
#define NULL_PTR
Null pointer.
Function to switch between user mode and privilege mode.
#define FSYS_SWITCH_TO_USER_MODE()
Switch back to user mode.
long FSYS_RaisePrivilege(void)
Raise privilege.
STD_RETURN_TYPE_e I2C_WriteDirect(uint32_t slaveAddress, uint32_t nrBytes, uint8_t *writeData)
writes to an I2C slave, no register address written first, blocking.
void I2C_SetStopNow(void)
sets stop condition.
STD_RETURN_TYPE_e I2C_ReadDma(uint32_t slaveAddress, uint8_t readAddress, uint32_t nrBytes, uint8_t *readData)
reads from an I2C slave, using DMA.
STD_RETURN_TYPE_e I2C_Write(uint32_t slaveAddress, uint8_t writeAddress, uint32_t nrBytes, uint8_t *writeData)
writes to an I2C slave, blocking.
STD_RETURN_TYPE_e I2C_ReadDirect(uint32_t slaveAddress, uint32_t nrBytes, uint8_t *readData)
reads from an I2C slave, no register address written first, blocking.
void I2C_Initialize(void)
STD_RETURN_TYPE_e I2C_WriteDma(uint32_t slaveAddress, uint8_t writeAddress, uint32_t nrBytes, uint8_t *writeData)
writes to an I2C slave, using DMA.
STD_RETURN_TYPE_e I2C_Read(uint32_t slaveAddress, uint8_t readAddress, uint32_t nrBytes, uint8_t *readData)
reads from an I2C slave, blocking.
Header for the driver for the I2C module.
#define I2C_TIMEOUT_ITERATIONS
Headers for the driver for the MCU module.
void OS_ExitTaskCritical(void)
Exit Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
void OS_EnterTaskCritical(void)
Enter Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.