volatile uint32_t msTicks=0; // counter for 1ms SysTicks
volatile unsigned char LED[5] = {0, 0, 0, 0, 0};
volatile unsigned char BUTTONS[8];
int main(void)
{
unsigned char IOCONF[5] = {0, 0, 0, 0, 0};
unsigned char Temp[2] = { 0xff, 0xff};
SetupI2CBlock();
PCA9545_SetCh(0, 0, 0, 0, 1);
PCA9505_Write(0, PCA9505_CMD_AI|PCA9505_CMD_IOC0, 5, (unsigned char*)IOCONF);
PCA9545_SetCh(0, 1, 0, 0, 0);
PCA8575_Write(0, (unsigned char*) Temp);
/* Systick rate is 1ms for timekeeping */
SysTick_Config(SystemCoreClock / 1000);
/* Blink for 5 seconds, then enter ISP */
while(1)
{
if (msTicks%100==0)
{
// Function
unsigned char TempButtons[2];
PCA9545_SetCh(0, 1, 0, 0, 0);
/******************************************/
// Problems begin here
// PCA8575_READ never overwrites Tempbuttons unless stepping through code manually in debugger
PCA8575_Read(0, (unsigned char*) TempButtons);
LED[0] = TempButtons[0];
LED[1] = TempButtons[1];
LED[2] = 0;
LED[3] = 0;
LED[4] = 0;
PCA9545_SetCh(0, 0, 0, 0, 1);
PCA9505_Write(0, PCA9505_CMD_AI|PCA9505_CMD_OP0, 5, (unsigned char*)LED);
}
__WFI();
}
return 0;
}
// ****************
// SysTick_Handler - just increment SysTick counter
void SysTick_Handler(void)
{
msTicks++;
}
|