Lecture 7 - Timers and Interrupts Review, SPI
Keep in mind:
- Try to keep pace with the current assignments
Today we'll review Timers and Interrupts, and get into SPI.
Timers and Interrupts
See Lecture 6 - Timers and Interrupts, especially look at:
So for instance:
void TIM2_IRQHandler(void)
{
//HAL_TIM_IRQHandler(&htim2);
TIM2->SR &= ~(TIM_SR_CC1IF);
TIM2->CCR1 += (1 << 19); // UPDATE THE CCR1 every tie we are interrupting. If
// ccr1 was say 100, then we get 1000....000 for the next count we interrupt.
if (GPIOA->ODR & GPIO_PIN_5)
GPIOA->BRR = GPIO_PIN_5;
else
GPIOA->BSRR = GPIO_PIN_5;
}
SPI
SPI stands for Serial-Peripheral Interface. Note that
- Serial means using one wire, transferring data bit per bit
- This is a synchronous design. Both devices communicating have the "same" clock signal, or some way to synchronize when to read/write the wire.
- This is a controller-based protocol. There'll be one device that's the controller to generate the clock. The controller will
There are 4 signals to consider for SPI:
/CS
or: Internal Chip Select SCK
: Synch. ClockSDO
: Serial Data OutSDI
: Serial Data In
We can have the following waveforms:
SPI is a circuit that's predesigned to work in this way, with its own configuration registers. You can also send out and receive data. All the clocking, /CS
, etc. is handled for you! You realistically could use GPIO to do this, but:
- It's been done before many a time
- A SW solution may not be as accurate.
One thing is that we drew a SCK
that's idle low (normally low), but sometimes we could have idle high instead. As a result, the falling and rising edges swap. Thus, since you always write to the rising edge, you can do this to choose if you actually want to write to the falling edge.