Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 231 → Rev 232

/PIC Stuff/PICX_16F1825_Controller/base_I2C.c
1,4 → 1,3
#include <xc.h>
#include "defines.h"
#include "base_I2C.h"
 
32,7 → 31,7
}
 
// Setup the PIC to operate as a master.
void I2C_Configure_Master(char speed) {
void I2C_Configure_Master(uint8_t speed) {
i2c_data_p->operating_mode = I2C_MODE_MASTER;
 
I2C_CLK_TRIS = 1;
52,8 → 51,8
}
 
// Sends length number of bytes in msg to specified address (no R/W bit)
void I2C_Master_Send(char address, char length, char *msg) {
char i;
void I2C_Master_Send(uint8_t address, uint8_t length, uint8_t *msg) {
uint8_t i;
if (length == 0)
return;
75,7 → 74,7
}
 
// Reads length number of bytes from address (no R/W bit)
void I2C_Master_Recv(char address, char length) {
void I2C_Master_Recv(uint8_t address, uint8_t length) {
if (length == 0)
return;
 
94,8 → 93,8
}
 
// Writes msg to address then reads length number of bytes from address
void I2C_Master_Restart(char address, char msg, char length) {
char c;
void I2C_Master_Restart(uint8_t address, uint8_t msg, uint8_t length) {
uint8_t c;
if (length == 0) {
c = msg;
I2C_Master_Send(address, 1, &c);
118,7 → 117,7
}
 
// Setup the PIC to operate as a slave. The address must not include the R/W bit
void I2C_Configure_Slave(char addr) {
void I2C_Configure_Slave(uint8_t addr) {
i2c_data_p->operating_mode = I2C_MODE_SLAVE;
 
// Ensure the two lines are set for input (we are a slave)
322,10 → 321,10
}
 
void I2C_Interrupt_Slave() {
char received_data;
char data_read_from_buffer = 0;
char data_written_to_buffer = 0;
char overrun_error = 0;
uint8_t received_data;
uint8_t data_read_from_buffer = 0;
uint8_t data_written_to_buffer = 0;
uint8_t overrun_error = 0;
 
// Clear SSPOV (overflow bit)
if (SSPCON1bits.SSPOV == 1) {
353,23 → 352,6
if (SSPSTATbits.S == 1) {
i2c_data_p->buffer_in_len_tmp = 0;
i2c_data_p->operating_state = I2C_STARTED;
// if (data_read_from_buffer) {
// if (SSPSTATbits.D_A == 1) {
// DBG_PRINT_I2C("I2C Start: (ERROR) no address recieved\r\n");
// // This is bad because we got data and we wanted an address
// i2c_data_p->operating_state = I2C_IDLE;
// i2c_data_p->return_status = I2C_ERR_NOADDR;
// } else {
// // Determine if we are sending or receiving data
// if (SSPSTATbits.R_W == 1) {
// i2c_data_p->operating_state = I2C_SEND_DATA;
// } else {
// i2c_data_p->operating_state = I2C_RCV_DATA;
// }
// }
// } else {
// i2c_data_p->operating_state = I2C_STARTED;
// }
}
break;
}
403,7 → 385,7
{
if (!i2c_data_p->slave_sending_data) {
// If we are not currently sending data, figure out what to reply with
if (I2C_Process_Send(i2c_data_p->slave_in_last_byte)) {
if (I2C_Process_Receive(i2c_data_p->slave_in_last_byte)) {
// Data exists to be returned, send first byte
SSPBUF = i2c_data_p->buffer_out[0];
i2c_data_p->buffer_out_ind = 1;
496,7 → 478,7
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns status code */
char I2C_Get_Status() {
uint8_t I2C_Get_Status() {
if (i2c_data_p->operating_mode == I2C_MODE_MASTER) {
if (i2c_data_p->master_status != I2C_MASTER_IDLE || i2c_data_p->buffer_in_len == 0) {
return 0;
512,13 → 494,13
}
}
 
char I2C_Buffer_Len() {
uint8_t I2C_Buffer_Len() {
return i2c_data_p->buffer_in_len;
}
 
/* Returns 0 if I2C module is currently busy, otherwise returns buffer length */
char I2C_Read_Buffer(char *buffer) {
char i = 0;
uint8_t I2C_Read_Buffer(uint8_t *buffer) {
uint8_t i = 0;
while (i2c_data_p->buffer_in_len != 0) {
buffer[i] = i2c_data_p->buffer_in[i2c_data_p->buffer_in_read_ind];
i++;
533,8 → 515,8
}
 
/* Put data to be returned here */
char I2C_Process_Send(char c) {
char ret = 0;
uint8_t I2C_Process_Receive(uint8_t c) {
uint8_t ret = 0;
BTN_STATUS btns;
switch (c) {
case CMD_QUERY_BTN: