No Clock on I2C LPC1115 - Page 1
Forum section: electronics / general

author: dreaquil
author_rank: Regular Contributor
timestamp: December 06, 2014, 07:08:55 pm
content: Hey,I have a project to do and been trying to set up the I2C peripheral on my LPC1115 to interface it to a 24LC014. I've had several problems which I've been able to solve but now I' stuck. I manage to start the I2C peripheral but I can't get an ACK bit back from the memory cause when I probe the SCL line its at about 0.8V constant. No idea what I'm doing wrong and been going through the datasheets for something I've missed over and over. Both the SCL and SDA are pulled up by a 10kohm (each) and I'm powering the 24LC014 from my micro. Heres my code:#include "LPC11xx.h"#include "board.h"// Create defines for simpler access of LED1#define DIR_REG0 LPC_GPIO0->DIR#define DATA_REG0 LPC_GPIO0->DATA#define IEV_REG0 LPC_GPIO0->IEV#define IE_REG0 LPC_GPIO0->IE#define IS_REG0 LPC_GPIO0->IS#define IC_REG0 LPC_GPIO0->IC#define IBE_REG0 LPC_GPIO0->IBE#define MIS_REG0 LPC_GPIO0->MIS#define TMR032_IR LPC_TMR32B0->IR //Interrupt Register#define TMR032_TCR LPC_TMR32B0->TCR //Timer control Register#define TMR032_TC LPC_TMR32B0->TC //Timer Counter#define TMR032_PR LPC_TMR32B0->PR //Prescale Register#define TMR032_PC LPC_TMR32B0->PC //Prescale Counter#define TMR032_MCR LPC_TMR32B0->MCR //Match Control Register#define TMR032_MR0 LPC_TMR32B0->MR0#define I2C_SCL LPC_IOCON->PIO0_4 //Control register for PIO0_4 (I2C Clock line)#define I2C_SDA LPC_IOCON->PIO0_5 //Control Register for PIO0_5 (I2C Address/Data line)#define I2C_SET LPC_I2C->CONSET#define I2C_DATA LPC_I2C->DAT#define I2C_CLR LPC_I2C->CONCLR#define I2C_STAT LPC_I2C->STAT#define I2C_HIGH LPC_I2C->SCLH#define I2C_LOW LPC_I2C->SCLL#define LED1 2#define SW 8#define LED_ON DATA_REG0 &= ~(1<<LED1);#define LED_OFF DATA_REG0 |= (1<<LED1);int toggle = 0;short data1=217;short ackno=0;void TIMER32_0_IRQHandler (void){if (toggle == 0){LED_ON;toggle = 1;}else{LED_OFF;toggle = 0;}//Clear Interrupt FlagTMR032_IR = 1;}void I2C_IRQHandler (void){LED_OFF;if(I2C_STAT == 0x08 ){//Transmit SLA and WriteI2C_CLR = 0x10; //Clear Start And Interrupt flagI2C_CLR = 0x3;}if(I2C_STAT == 0x18){ //Transmit Data if ACK bit ReceivedI2C_DATA = data1; //Place data in data registerI2C_CLR |= (1<<5); //Clear Start BitI2C_CLR = 0x4; //Clear Interrupt Flag}if(I2C_STAT == 0x20){ //Restart transmission if ACK bit ReceivedI2C_SET |= (1<<4); //Set Stop BitI2C_CLR = 0x4; //Clear Interrupt Flag}if(I2C_STAT == 0x38){ //Restart transmission if Arbitration lostI2C_SET |= (1<<5); //Set Start BitI2C_CLR = 0x4; //Clear Interrupt Flag}if(I2C_STAT == 0x28){ //Restart transmission if Arbitration lostI2C_SET |= (1<<4); //Set Stop BitI2C_CLR |= (1<<3);//Clear Interrupt Flag}}void setup_I2C(void){LPC_SYSCON->PRESETCTRL |= (1<<1); //De-assert Reset for I2CI2C_SCL |= (1<<0);//I2C Standard ModeI2C_SDA |= (1<<0);//I2C Standard ModeLPC_SYSCON->SYSAHBCLKCTRL |= (1<<5); //Enables clock for I2CNVIC_EnableIRQ(I2C_IRQn);I2C_HIGH = 0b11110000; //Set SCLH =240 for total period of 480 (Standard Mode)I2C_LOW = 0b11110000;I2C_SET |= (1<<6); //Set Enable I2C InterfaceI2C_CLR = 0x4; //Clear Interrupt FlagI2C_DATA = 0b10100000;//Control code (0b1010) of Slave and address 0b000, WriteI2C_CLR = 0x10; //Clear Start Bit//Setting I2C as Master Transmitter mode}void write_I2C(void){I2C_SET|=(1<<5); //Set Start Bit}void setup_TMR032(void){LPC_SYSCON->SYSAHBCLKCTRL |= (1<<9);//Enable the update interrupt and resetTMR032_MCR |= (1<<0);TMR032_MCR |= (1<<1);//Set Prescalar to 0TMR032_PR = 0x0;//Set match register 0 to 25000000TMR032_MR0 = 0x16E3600;// Set Rising EdgeIEV_REG0 |= (1<<SW);// Enable interrupt on pinIE_REG0 |= (1<<SW);//Reset CounterTMR032_TCR |= (1<<1);TMR032_TCR &= ~(1<<1);//Enable CounterTMR032_TCR |= (1<<0);//Clear Interrupt FlagTMR032_IR = 1;// NVIC_EnableIRQ(EINT0_IRQn);NVIC_EnableIRQ(TIMER_32_0_IRQn);}int main (void){// Set PIO_0_2 as outputDIR_REG0 |= (1<<LED1);// Set Switch as inputDIR_REG0 &= ~(1<<SW);setup_I2C();LED_ON;while(1){if(ackno == 0){write_I2C();LED_ON;ackno = 1;}asm("nop;");};return 0;}EDIT: I'm not using the timer at the moment... thats something ill be using later on in the project

author: dannyf
author_rank: Super Contributor
timestamp: December 07, 2014, 12:43:56 am
content: QuoteI think the 2nd statement would suggest otherwise, unless you didn't measure the voltage right.Many people find it beneath them but can you blink an led on that set-up?

author: dreaquil
author_rank: Regular Contributor
timestamp: December 07, 2014, 05:24:28 pm
content: nothings beneath me haha Yes i've been able to turn on an LED in the ISR of the I2C