Source code file for I2C module.
More...
Go to the source code of this file.
Source code file for I2C module.
Definition in file i2c.c.
◆ I2C_masterISR()
__interrupt void I2C_masterISR |
( |
void |
| ) |
|
I2C ISR-Routine in master mode when NACK detected.
- Parameters
-
- Returns
- /
Definition at line 243 of file i2c.c.
246 TMC_BASE_I2C->MDR &= ~(0x1 << 5);
247 TMC_BASE_I2C->MDR |= (0x1 << 5);
249 TMC_BASE_I2C->FFTX &= ~(0x1<<14);
250 TMC_BASE_I2C->FFTX &= ~(0x1<<13);
251 TMC_BASE_I2C->FFTX |= (0x1<<14);
252 TMC_BASE_I2C->FFTX |= (0x1<<13);
254 while(TMC_BASE_I2C->STR & 0x1000);
255 TMC_BASE_PIE->ACK |= 0x0080;
◆ I2C_readDataAsMaster()
Read data in I2C master mode from slave.
- Parameters
-
[in] | | 1) Pointer to I2CMSG_transmit
|
- Returns
- int16
--> 0 = operation successful
--> -18 = I2C module is disabled
Definition at line 194 of file i2c.c.
197 if(!(TMC_BASE_I2C->MDR & 0x0020)){
201 while(TMC_BASE_I2C->STR & 0x1000);
203 TMC_BASE_I2C->MDR |= (0x1<<10);
204 TMC_BASE_I2C->MDR |= (0x1<<9);
215 TMC_BASE_I2C->MDR |= (0x1<<13);
217 while((TMC_BASE_I2C->FFTX & 0x1F00) > 0);
220 TMC_BASE_I2C->MDR &= ~(0x1<<9);
221 TMC_BASE_I2C->MDR |= (0x1<<11);
222 TMC_BASE_I2C->MDR |= (0x1<<13);
226 while(!(TMC_BASE_I2C->FFRX & 0x0080)){
229 msg->
Data[i] = TMC_BASE_I2C->DRR;
230 __asm(
" RPT #255 || NOP");
231 TMC_BASE_I2C->FFRX |= (0x1 << 6);
◆ I2C_slaveISR()
__interrupt void I2C_slaveISR |
( |
void |
| ) |
|
I2C ISR-Routine in slave mode when Adressed detected.
receives register-address and values und writesv alue into register.
sends data from requested register to I2C Bus when addressed as slave transmitter.
- Parameters
-
- Returns
- /
Definition at line 265 of file i2c.c.
271 static Uint16 previous_register_address = 0x0000;
272 Uint16 register_address = 0x0000;
273 Uint16 register_value = 0x0000;
276 IntSource = (TMC_BASE_I2C->ISRC & 0x0007);
280 while(!(TMC_BASE_I2C->FFRX & 0x0080) && !stop){
281 if(TMC_BASE_I2C->STR & 0x0020){
289 register_address |= TMC_BASE_I2C->DRR;
291 register_address = (register_address<<8);
293 TMC_BASE_I2C->FFRX |= (0x1 << 6);
295 __asm(
" RPT #255 || NOP");
299 if(!(TMC_BASE_I2C->STR & 0x4000)){
300 TMC_BASE_I2C_register = (TM_CAST(
TMPS_I2C_Reg) register_address);
302 while(!(TMC_BASE_I2C->FFRX & 0x0080) && !stop){
303 if(TMC_BASE_I2C->STR & 0x0020){
312 register_value = (
Uint16) (TMC_BASE_I2C->DRR);
315 register_value |= ((
Uint16) TMC_BASE_I2C->DRR<<8);
319 TMC_BASE_I2C->FFRX |= (0x1 << 6);
321 __asm(
" RPT #255 || NOP");
326 TMC_BASE_I2C_register = (TM_CAST(
TMPS_I2C_Reg) previous_register_address);
327 TMC_BASE_I2C->MDR |= (0x1<<9);
330 while(TMC_BASE_I2C->FFTX & 0x0080){
331 if(TMC_BASE_I2C->STR & 0x0020){
332 TMC_BASE_I2C->MDR &= ~(0x1<<9);
336 TMC_BASE_I2C->MDR &= ~(0x1<<9);
343 previous_register_address = register_address;
344 TMC_BASE_PIE->ACK |= 0x0080;
◆ I2C_writeDataAsMaster()
Send data in I2C master mode to slave.
- Parameters
-
[in] | | 1) Pointer to I2CMSG_transmit
|
- Returns
- int16
--> 0 = operation successful
--> -18 = I2C module is disabled
Definition at line 143 of file i2c.c.
146 if(!(TMC_BASE_I2C->MDR & 0x0020)){
150 while(TMC_BASE_I2C->STR & 0x1000);
152 TMC_BASE_I2C->MDR |= (0x1<<10);
153 TMC_BASE_I2C->MDR |= (0x1<<9);
166 TMC_BASE_I2C->DXR = *(msg->
Data+i);
169 TMC_BASE_I2C->MDR |= (0x1<<11);
170 TMC_BASE_I2C->MDR |= (0x1<<13);
172 for(i=0; i<800; i++){
173 __asm(
" RPT #255 || NOP");
176 while(TMC_BASE_I2C->STR & 0x1000);
178 if(TMC_BASE_I2C->FFTX & 0x1F00){
179 TMC_BASE_I2C->FFTX &= ~(0x1<<14);
180 TMC_BASE_I2C->FFTX &= ~(0x1<<13);
181 TMC_BASE_I2C->FFTX |= (0x1<<14);
182 TMC_BASE_I2C->FFTX |= (0x1<<13);
◆ init_I2CMasterMode()
Initialization of I2C Interface master mode.
- Parameters
-
- Returns
- int16
--> 0 = operation successful
--> -1 = I2C.sda invalid value
--> -2 = I2C.scl invalid value
Definition at line 23 of file i2c.c.
25 case 32:
switch(I2C.
scl){
27 TMC_BASE_PIO->CTL[1].PUD &= ~(0x1);
28 TMC_BASE_PIO->CTL[1].QSEL1 &= ~(0x3<<0);
29 TMC_BASE_PIO->CTL[1].MUX1 |= (0x1<<0);
31 TMC_BASE_PIO->CTL[1].PUD &= ~(0x1);
32 TMC_BASE_PIO->CTL[1].QSEL1 &= ~(0x3<<2);
33 TMC_BASE_PIO->CTL[1].MUX1 |= (0x1<<2);
36 TMC_BASE_I2C->MDR &= ~(0x0020);
38 TMC_BASE_I2C->PSC = 0xE;
39 TMC_BASE_I2C->CLKL = 35;
40 TMC_BASE_I2C->CLKH = 55;
42 TMC_BASE_I2C->IER = (0x1 << 1);
43 TMC_BASE_I2C->MDR |= (0x1<<10);
45 TMC_BASE_I2C->FFTX |= (0x1<<14);
46 TMC_BASE_I2C->FFTX |= (0x1<<13);
48 TMC_BASE_I2C->FFRX |= (0x1<<13);
49 TMC_BASE_I2C->FFRX |= (0x1);
50 TMC_BASE_I2C->FFRX |= (0x1 << 6);
56 TMC_BASE_PIE->CTRL |= 0x01;
57 TMC_BASE_PIE->GROUP[7].IER |= 0x1;
61 TMC_BASE_I2C->MDR |= (0x1 << 5);
◆ init_I2CSlaveMode()
Initialization of I2C Interface slave mode.
- Parameters
-
[in] | | 1) I2CInterface I2C
2) Uint16 slave_address
|
- Returns
- int16
--> 0 = operation successful
--> -1 = I2C.sda invalid value
--> -2 = I2C.scl invalid value
Definition at line 81 of file i2c.c.
83 case 32:
switch(I2C.
scl){
85 TMC_BASE_PIO->CTL[1].PUD &= ~(0x1);
86 TMC_BASE_PIO->CTL[1].QSEL1 |= (0x3<<0);
87 TMC_BASE_PIO->CTL[1].MUX1 |= (0x1<<0);
89 TMC_BASE_PIO->CTL[1].PUD &= ~(0x1<<1);
90 TMC_BASE_PIO->CTL[1].QSEL1 |= (0x3<<2);
91 TMC_BASE_PIO->CTL[1].MUX1 |= (0x1<<2);
94 TMC_BASE_I2C->MDR &= ~(0x0020);
96 TMC_BASE_I2C->PSC = 0xE;
97 TMC_BASE_I2C->CLKL = 35;
98 TMC_BASE_I2C->CLKH = 55;
99 TMC_BASE_I2C->IER = (0x1 << 6);
101 TMC_BASE_I2C->FFTX |= (0x1<<14);
102 TMC_BASE_I2C->FFTX |= (0x1<<13);
103 TMC_BASE_I2C->FFTX &= ~(0x1F);
104 TMC_BASE_I2C->FFTX |= (0x1 << 6);
106 TMC_BASE_I2C->FFRX |= (0x1<<13);
107 TMC_BASE_I2C->FFRX |= (0x1);
108 TMC_BASE_I2C->FFRX |= (0x1 << 6);
110 TMC_BASE_I2C->OAR = slave_address;
112 TMC_BASE_I2C->MDR &= ~(0x1<<3);
113 TMC_BASE_I2C->MDR &= ~(0x1<<8);
114 TMC_BASE_I2C->MDR &= ~(0x1<<10);
120 TMC_BASE_PIE->CTRL |= 0x01;
121 TMC_BASE_PIE->GROUP[7].IER |= 0x1;
125 TMC_BASE_I2C->MDR |= 0x0020;