void i2c_setup(void)
{
	/* Setup I2C pin muxing */
	Init_I2C_PinMux();

	/* Setup I2C, master, and slave */
	setupI2CMaster();
  setupI2CSlave();

	/* Enable the interrupt for the I2C */
	NVIC_EnableIRQ(LPC_IRQNUM);
		
	xI2cSemaphore =xSemaphoreCreateBinary();
	

	DEBUGOUT(" I2C slaves are ready\r\n");
}
Example #2
0
/**
 * @brief	Main routine for I2C example
 * @return	Function should not exit
 */
int main(void)
{
	int lastState = -1;

	/* Generic Initialization */
	SystemCoreClockUpdate();
	Board_Init();

	Board_LED_Set(0, false);

	/* Setup I2C pin muxing */
	Init_I2C_PinMux();

	/* Allocate I2C handle, setup I2C rate, and initialize I2C
	   clocking */
	setupI2CMaster();

	/* Enable the interrupt for the I2C */
	NVIC_EnableIRQ(I2C_IRQn);

	/* Enable SysTick Timer */
	SysTick_Config(SystemCoreClock / TICKRATE_HZ);

	//ustawiamy przykładowo godzinę 9:31
	volatile int hourH = 0;
	volatile int hourL = 9;
	volatile int minuteH = 3;
	volatile int minuteL = 1;
	volatile int seconds = 0;
	volatile int tickCounter = 0;

	/* Toggle LED on other board via I2C */
	while (1) {

		//zliczanie ticków
		tickCounter++;

		//kolejno warunki na zliczanie sekund, minut, godzin
		//w przypadku taktowania 400 ticków na sekundę
		if(tickCounter == 400) {
			tickCounter = 0;
			seconds = seconds + 1;
		}
		if(seconds == 60) {
			seconds = 0;
			minuteL = minuteL + 1;
		}
		if(minuteL == 10) {
			minuteL = 0;
			minuteH = minuteH + 1;
		}
		if(minuteH == 6) {
			minuteH = 0;
			hourL = hourL + 1;
		}
		if(hourL == 10) {
			hourL = 0;
			hourH = hourH + 1;
		}
		if(hourH == 2 && hourL == 4) {
			minuteH = 0; minuteL = 0;
			hourL = 0; hourH = 0;
		}

		//wyświetlanie aktualnej godziny
		showNumber(minuteL,LED0);
		showNumber(minuteH,LED1);
		showNumber(hourL,LED2);
		showNumber(hourH,LED3);

		/* Handle states */
		switch (state) {
		case 0:
			/* Toggle LED state value */
			ledState = (ledState == 0);
			break;

		case 1:
		default:
			break;
		}

		lastState = state;

		/* Match this board's LED to other boards state */
		Board_LED_Set(0, ledState);
	}
}