|
|
Component
SynchroSlave
Slave for synchronous serial communication
Component Level: High
Category:
CPU Internal Peripherals-Communication
Typical Usage:
(Examples of a typical usage of the component in user code.
For more information please
see the page Component Code
Typical Usage.)
Required component name is "SS1". The following three typical usage modes are:
(1)
MAIN.C
SS1_TComData ch;
byte err;
void main(void)
{
for (;;) {
while (SS1_GetCharsInRxBuf() == 0); //Wait for a character
err = SS1_RecvChar(&ch); // Get received character
if ((err == ERR_OK) || (err == ERR_OVERRUN)) {
SS1_SendChar(ch); // Prepare a character for transmision
}
}
}
(2)
EVENTS.C
void AM1_OnRxChar(void)
{
SS1_TComData ch;
byte err;
err = SS1_RecvChar(&ch); // Get received character
if ((err == ERR_OK) || (err == ERR_OVERRUN)) {
SS1_SendChar(ch); // Prepare a character for transmision
}
}
(3)
MAIN.C
SS1_TComData ch;
byte err;
void main(void)
{
for (;;) {
while (SS1_GetCharsInRxBuf() == 0); //Wait for a character
err = SS1_RecvChar(&ch); // Get received character
if ((err == ERR_OK) || (err == ERR_OVERRUN)) {
SS1_SendChar(ch); // Prepare a character for transmision
}
}
}
EVENTS.C
void SS1_OnError(void)
{
SS1_TError error; //TError union is defined in the header file
/* Read the last communication errors */
SS1_GetError(&error);
/* If error OverRun occured then ... */
if(error.errName.OverRun) {
/* Error handling */
}
}
(4)
MAIN.C
#define BLOCK_LENGTH 10
SS1_TComData SampleBlock[BLOCK_LENGTH];
word Snt, Rcv;
void main(void)
{
/* Enable DMA transfer from the receiver */
(void)SS1_RecvBlock(&SampleBlock[0],BLOCK_LENGTH,&Rcv);
/* Send block of samples using DMA support */
(void)SS1_SendBlock(&SampleBlock[0],BLOCK_LENGTH,&Snt);
/* Wait for transmit/receive BLOCK_LENGTH samples */
/* Note: It is clocked by master (SynchroMaster) */
while (SS1_GetCharsInRxBuf() < BLOCK_LENGTH) {};
}
|