I'm using a K20D72M tower and I'm trying to implement the I2C component into my code and I am basing my code off of the demo i2c code found in C:\Freescale\CW MCU v10.3\MCU\CodeWarrior_Examples\Processor_Expert\Kinetis\TWR-K20D72M. I'm attempting to replicate the components used in that demo i2c code but I'm running into errors with the Timer and a little confused with how the new LDD components work along with how the timer component is working.
Attached is a screen shot of the errors I'm getting while trying to set up the timer, from what I understand the counter frequency must be 36 MHz since my chip is 72 MHz core speed.
The biggest reason why I'm confused with how the timer works is because in the demo i2c code, the function to read from it works with the timer like this...
LINE 63: DataState->Sent = FALSE;
LINE 64: I2C_MasterSendBlock(I2CPtr, &Address, sizeof(Address), LDD_I2C_NO_SEND_STOP);
LINE 65: while (!DataState->Sent && !Timeout(TimerPtr)) {}
LINE 66: TIMER_ResetCounter(TimerPtr);
LINE 67: if (!DataState->Sent) {
LINE 68: printf("ERROR Transmission timed out\n");
LINE 69: return FALSE;
LINE 70: }
I understand line 65 how it is waiting for the timer to time out and the DataState to be sent correctly but on line 66, why is it calling the ResetCounter function? Does the timer need to be manually reset to 1 second or does it set on it's own when the timer is called?
Thank you, I'm sorry it's a bunch of questions at once.
Hello,
you can get all possible values for counter frequency if you click on the property and then click on the three dots on the right inside the edit box. They depend on the selected type of counter (timer module). For PIT only the bus clock is available. The ResetCounter function resets the timeout counter, so it starts counting to 1 second again, from 0 second. Then the next while should have 1 second until it fails (in the case that the communication has failed). ResetCounter would be probably better placed before MasterSendBlock.
Best regards,
Ladislav Vadkerti