Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LG by
Diff: DeviceI2C.c
- Revision:
- 186:c7a9c309086c
- Parent:
- 167:bedc0a9d559a
--- a/DeviceI2C.c Sun Jul 10 05:35:08 2016 +0000
+++ b/DeviceI2C.c Sun Jul 31 06:19:02 2016 +0000
@@ -11,7 +11,7 @@
#define I2CONCLR_SIC 0x0000008
#define I2CONCLR_STAC 0x0000020
#define I2CONCLR_I2ENC 0x0000040
-//I2C SCL Duty Cycle High Reg
+//I2C SCL Duty Cycle Register
#define I2SCLH_SCLH 0x00000080 //High
#define I2SCLL_SCLL 0x00000080 //Low
//Address
@@ -24,7 +24,7 @@
extern Device device;
//
-//Warning!!!
+//Attention!!!
// Different LPC17xx.h versions declare different I2C registers names:
// LPC_I2C0->CONCLR (Keil?)/ LPC_I2C0->I2CONCLR (mbed)
// ...
@@ -37,21 +37,19 @@
void InitI2CState(void) {
device.controller.I2C.state.buffer[0] = I2C_A_ADDRESS;
device.controller.I2C.state.buffer[1] = I2C_WRITE_CMD;
- device.controller.I2C.state.buffer[2] = device.isacs.potentiometers.settings.a;
+ device.controller.I2C.state.buffer[2] = 255 - device.isacs.potentiometers.settings.a;
device.controller.I2C.state.buffer[3] = I2C_B_ADDRESS;
device.controller.I2C.state.buffer[4] = I2C_WRITE_CMD;
- device.controller.I2C.state.buffer[5] = device.isacs.potentiometers.settings.b;
+ device.controller.I2C.state.buffer[5] = 255 - device.isacs.potentiometers.settings.b;
device.controller.I2C.state.position = 0;
device.controller.I2C.state.counter = 0;
device.controller.I2C.state.trigger = device.controller.I2C.settings.trigger;
+ device.controller.I2C.state.enabled = 0;
}
void DeviceStartI2C(void) {
- LPC_SC->PCONP |= (1 << 7);//I2C0 on
- //LPC_SC->PCONP |= (1 << 19);//I2C1 on
+ LPC_SC->PCONP |= (1 << 7);//I2C0 power on
- // set PIO0.27 and PIO0.28 to I2C0 SDA and SCK
- // function to 01 on both SDA and SCK
LPC_PINCON->PINSEL1 &= ~0x03C00000; //P0.27 - SDA
LPC_PINCON->PINSEL1 |= 0x01400000; //P0.28 - SCK
@@ -67,11 +65,12 @@
//LPC_I2C0->I2CONSET = I2CONSET_I2EN; //включение интерфейса I2C
device.controller.I2C.state.CON0 = LPC_I2C0->CONSET & (~LPC_I2C0->CONCLR);
- //device.controller.I2C.state.CON0 = LPC_I2C0->I2CONSET & (~LPC_I2C0->I2CONCLR);
+
+ i2cEnableTransmission();
}
-void DeviceI2CTransmit(void) {
- if (!device.controller.I2C.state.enabled) return; //Transmission disabled, go away
+void i2cProcess(void) {
+ if (!device.controller.I2C.state.enabled) return; //Transmission disabled, go away
device.controller.I2C.state.counter++;
if (device.controller.I2C.state.counter > device.controller.I2C.state.trigger){//Time out, go away
@@ -118,19 +117,17 @@
//ACK after data byte
case 0x28:
- if (device.controller.I2C.state.position == I2C_BUFFER_LENGTH) { //Data transmission finished
+ if (device.controller.I2C.state.position == I2C_BUFFER_LENGTH) { //Data transmission finished
device.controller.I2C.state.enabled = 0;
LPC_I2C0->CONSET = I2CONSET_STO; //Set Stop flag
//LPC_I2C0->I2CONSET = I2CONSET_STO; //Set Stop flag
- //Output.Str.Cnt_Dif = 300;
} else if (device.controller.I2C.state.position == 3) {
LPC_I2C0->CONSET = I2CONSET_STA;
//LPC_I2C0->I2CONSET = I2CONSET_STA;
- //Output.Str.Cnt_Dif = 200;
+ //sprintf(device.service.buffer, "I2C 0x28 mid\r\n"); WriteConcole(); //Development message
} else {
LPC_I2C0->DAT = device.controller.I2C.state.buffer[device.controller.I2C.state.position++];//Send another byte
//LPC_I2C0->I2DAT = device.controller.I2C.state.buffer[device.controller.I2C.state.position++];//Send another byte
- //Output.Str.Cnt_Dif = 100;
}
LPC_I2C0->CONCLR = I2CONCLR_SIC; //Clear interrupt bit
//LPC_I2C0->I2CONCLR = I2CONCLR_SIC; //Clear interrupt bit
@@ -144,15 +141,15 @@
//LPC_I2C0->I2CONSET = I2CONSET_STO; //Set Stop flag
LPC_I2C0->CONCLR = (I2CONCLR_SIC | I2CONCLR_STAC);
//LPC_I2C0->I2CONCLR = (I2CONCLR_SIC | I2CONCLR_STAC);
- device.controller.I2C.state.enabled = 0; //Disable transmission
+ device.controller.I2C.state.enabled = 0; //Disable transmission
break;
}
}
-void StartI2CTransmission(void){
+void i2cEnableTransmission(void){
device.controller.I2C.state.position = 0;
- device.controller.I2C.state.counter = I2C_TIMEOUT;
+ device.controller.I2C.state.counter = 0;
LPC_I2C0->CONSET = I2CONSET_STA; //Set start flag
//LPC_I2C0->I2CONSET = I2CONSET_STA; //Set start flag
- device.controller.I2C.state.enabled = 1; //Enable transmission
+ device.controller.I2C.state.enabled = 1; //Enable transmission
}
\ No newline at end of file
