EasyManua.ls Logo

ST ST7 - Initialization of the Peripherals and the Parameters

ST ST7
317 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
310/317
10 - Second Application: a Sailing Computer
If the interrupt cause is the reception of a character, the interrupt request is cleared by reading
the Status Register (which is done when it is tested), then reading the Data Register. The
character received is copied to the global variable
RemoteCommand that is used by the main
program.
If the interrupt cause is the transmit buffer being empty, the interrupt request is cleared by
reading the Status Register, and writing the nextcharacter from the bufferto the Data Register
of the SCI. The buffer index is incremented for next time.
The value of the character is tested, and if it is a Line Feed character, meaning it is the last
character of the message, the transmit interrupt is masked out, so that no further interrupts will
be generated.
The main program tests the value of
RemoteCommand and, if it belongs to the predefined vo-
cabulary (W, w, D, d, B, V), the requested value is calculated, converted to an ASCII string,
and put into the buffer. Then, the
RemoteCommand variableisresettozero,theTransmitBuffer
index is reset to zero (the beginning of the buffer) and the Transmit Buffer Empty interrupt is
enabled. This triggers interrupt servicing immediately, since the request is already pending,
and the first character is sent immediately.
This way of handling the SCI is both fast and memory-efficient: the interrupt service routine
just copies a character from one address to another. It is the main program that calculates the
string to be sent as the response to the request received, and this can be done when the core
has the time to do it. Thus serial communication occurs at exactly the speed the core can
handle and does not impede meeting the stringent requirements for interrupt latency required
by the frequency measurement. The display refresh, which must be done at regular intervals,
is also not affected whatever the number of requests received from the computer.
10.5.8 Initialization of the peripherals and the parameters
The initialization calls for few comments. Initialization of Timer A in PWM mode is done with
this function:
void InitTimerA ( void )
{
TACR1=(1<<TOIE ) ; /* Overflow interrupt enabled */
TACR2=(1<<PWM); /*PWMmode, clock divided by 4 */
TAOC2HR = REFRESH_PERIOD >> 8 ;
TAOC2LR = REFRESH_PERIOD & 0xff ;
}
Please note that the order of the loading of the compare register is important. When the high-
order byte is written, the comparisons are inhibited until the low-order byte is also written. This
implies that the high byte must be written first, in order to have the PWM mode work.

Table of Contents

Related product manuals