Hallo Zusammen,
Ich wollte zwischen zwei Pic18F46k42 über I2C 8Bit werte austauschen,
jedoch bekomme ich keinen Interrupt am Slave. Die Adresse ist auf dem
Bus, hab ich gemessen. Konfiguriert hab ichs mit dem MCC.
Mastercode:
1 | #include "mcc_generated_files/mcc.h"
|
2 | #include "mcc_generated_files/examples/i2c1_master_example.h"
|
3 |
|
4 | /*
|
5 | Main application
|
6 | */
|
7 | void main(void)
|
8 | {
|
9 | // Initialize the device
|
10 | SYSTEM_Initialize();
|
11 |
|
12 | // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
|
13 | // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global Interrupts
|
14 | // Use the following macros to:
|
15 |
|
16 | // Enable the Global Interrupts
|
17 | //INTERRUPT_GlobalInterruptEnable();
|
18 |
|
19 | // Disable the Global Interrupts
|
20 | //INTERRUPT_GlobalInterruptDisable();
|
21 |
|
22 | while (1)
|
23 | {
|
24 | I2C1_Write1ByteRegister(8, 0, 1);
|
25 | }
|
26 | }
|
Slavecode:
1 | #include "mcc_generated_files/mcc.h"
|
2 |
|
3 | /*
|
4 | Main application
|
5 | */
|
6 | void I2C_Int(void);
|
7 |
|
8 | void main(void)
|
9 | {
|
10 | // Initialize the device
|
11 | SYSTEM_Initialize();
|
12 |
|
13 | FET_LAT = 0;
|
14 |
|
15 | // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
|
16 | // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global Interrupts
|
17 | // Use the following macros to:
|
18 |
|
19 | // Enable the Global Interrupts
|
20 | INTERRUPT_GlobalInterruptEnable();
|
21 |
|
22 | // Disable the Global Interrupts
|
23 | //INTERRUPT_GlobalInterruptDisable();
|
24 |
|
25 | I2C1_SlaveSetAddrIntHandler(I2C_Int);
|
26 | I2C1_SlaveSetIsrHandler(I2C_Int);
|
27 |
|
28 |
|
29 | I2C1_Enable();
|
30 | I2C1_Open();
|
31 |
|
32 | while (1)
|
33 | {
|
34 | I2C1_Read();
|
35 | }
|
36 | }
|
37 |
|
38 | void I2C_Int(void)
|
39 | {
|
40 | FET_LAT = 1;
|
41 | }
|