|
|
Component
SynchroMaster
Master 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 "SM1". The following four typical usage modes are:
(1)
MAIN.C
TComData ch;
byte err;
void main(void)
{
do {
SM1_SendChar(0); // Send zero
err = SM1_RecvChar(&ch); // Get received char
/* Do until it receives char with code 13 */
} while ( (err != ERR_OK) || (ch != 13) );
}
(2)
MAIN.C
volatile bool Flag;
void main(void)
{
Flag = FALSE;
do {
SM1_SendChar(0); // Send zero
/* Do until it receives char with code 13 */
} while (!Flag);
}
EVENTS.C
extern bool Flag;
void AM1_OnRxChar(void)
{
byte ch;
byte err;
err = SM1_RecvChar(&ch); // Get received char
/* If it receives char with code 13 then Flag is set to TRUE */
if ( (err == ERR_OK) && (ch == 13) ){
Flag = TRUE;
}
}
(3)
MAIN.C
TComData ch;
void main(void)
{
do {
SM1_SendChar(0); // Send zero
err = SM1_RecvChar(&ch); // Get received char
/* Do until it receives char with code 13 */
} while ( (err != ERR_OK) || (ch != 13) );
}
EVENTS.C
void SM1_OnError(void)
{
SM1_TError error; //TError union is defined in the header file
/* Read the last communication errors */
SM1_GetError(&error);
/* If error OverRun occured then ... */
if(error.errName.OverRun) {
/* Error handling */
}
}
(4)
MAIN.C
#define BLOCK_LENGTH 10
SM1_TComData SampleBlock[BLOCK_LENGTH];
word Snt, Rcv;
void main(void)
{
/* Enable DMA transfer from the receiver */
(void)SM1_RecvBlock(&SampleBlock[0],BLOCK_LENGTH,&Rcv);
/* Send block of samples using DMA support */
(void)SM1_SendBlock(&SampleBlock[0],BLOCK_LENGTH,&Snt);
/* Wait for transmit/receive BLOCK_LENGTH samples */
while (SM1_GetCharsInRxBuf() < BLOCK_LENGTH) {};
}
|