Subversion Repositories Code-Repo

Rev

Rev 281 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 281 Rev 282
Line 4... Line 4...
4
extern I2C1_DATA i2c_data;
4
extern I2C1_DATA i2c_data;
5
 
5
 
6
// Set up the data structures for the base_I2C.code
6
// Set up the data structures for the base_I2C.code
7
// Should be called once before any i2c routines are called
7
// Should be called once before any i2c routines are called
8
void I2C1_Init(void) {
8
void I2C1_Init(void) {
-
 
9
    I2C_1_CLK_TRIS = 1;
-
 
10
    I2C_1_DAT_TRIS = 1;
-
 
11
    
9
    i2c_data.buffer_in_len = 0;
12
    i2c_data.buffer_in_len = 0;
10
    i2c_data.buffer_in_read_ind = 0;
13
    i2c_data.buffer_in_read_ind = 0;
11
    i2c_data.buffer_in_write_ind = 0;
14
    i2c_data.buffer_in_write_ind = 0;
12
    
15
    
13
    i2c_data.operating_state = I2C_IDLE;
16
    i2c_data.operating_state = I2C_IDLE;
Line 20... Line 23...
20
    PIE1bits.SSP1IE = 1;
23
    PIE1bits.SSP1IE = 1;
21
}
24
}
22
 
25
 
23
// Setup the PIC to operate as a master.
26
// Setup the PIC to operate as a master.
24
void I2C1_Configure_Master(uint8_t speed) {
27
void I2C1_Configure_Master(uint8_t speed) {
25
//    i2c_data.operating_mode = I2C_MODE_MASTER;
-
 
26
 
-
 
27
    I2C_1_CLK_TRIS = 1;
-
 
28
    I2C_1_DAT_TRIS = 1;
-
 
29
 
-
 
30
    SSP1STAT = 0x0;
28
    SSP1STAT = 0x0;
31
    SSP1CON1 = 0x0;
29
    SSP1CON1 = 0x0;
32
    SSP1CON2 = 0x0;
30
    SSP1CON2 = 0x0;
33
    SSP1CON3 = 0x0;
31
    SSP1CON3 = 0x0;
34
    SSP1CON1bits.SSPM = 0x8; // I2C Master Mode
32
    SSP1CON1bits.SSPM = 0x8; // I2C Master Mode