Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 275 → Rev 276

/PIC Stuff/Cerebot_32MX7_LED_Cube/I2C1.c
29,11 → 29,22
// Note: Automatically overrides any other pin settings
I2C1CONSET = 0x00008040;
I2C1ADD = address;
if (!speed) I2C1BRG = 0x05A; // Operate at 400kHZ (80MHz)
else I2C1BRG = 0x186; // Operate at 100kHZ (80MHz)
if (speed == 0x01) {
I2C1BRG = 0x0BE; // Operate at 200kHZ (80MHz)
I2C1CONbits.DISSLW = 0; // Slew rate control enabled
} else if (speed == 0x02) {
I2C1BRG = 0x05A; // Operate at 400kHZ (80MHz)
I2C1CONbits.DISSLW = 1; // Slew rate control disabled
} else if (speed == 0x03) {
I2C1BRG = 0x020; // Operate at 1MHz (80MHz)
I2C1CONbits.DISSLW = 1; // Slew rate control disabled
} else {
I2C1BRG = 0x186; // Operate at 100kHZ (80MHz)
I2C1CONbits.DISSLW = 0; // Slew rate control enabled
}
IFS0CLR = 0xE0000000; // Clear any existing events
IPC6CLR = 0x00001F00; // Reset priority levels
IPC6SET = 0x00001500; // Set IPL=5, Subpriority 1
IPC6SET = 0x00001600; // Set IPL=6, Subpriority 2
IEC0SET = 0xE0000000; // Enable I2C1 interrupts
 
INTEnableInterrupts();
249,7 → 260,8
// Check if ACK is received or not
if (!I2C1STATbits.ACKSTAT) {
// If an ACK is received, send first byte of data
I2C1TRN = i2c_data_p->buffer_in[0];
uint8_t to_send = i2c_data_p->buffer_in[0];
I2C1TRN = to_send;
i2c_data_p->operating_state = I2C1_CHECK_ACK_RESTART;
} else {
// If a NACK is received, stop transmission and send error