UART ON SYNERGY SK-S7G2
次に定番のUARTを使っています。SK-S7G2は、SCI3をRS-232SかRS-485に使用できます。RS-232C側は、トランシーバにつながっています。。TTLレベルで通信したかったのでRS-485の設定にしてP76、P77ピンで通信しました。
まずUART用のスレッドを追加します。
UARTDriver on r_spi_uart
Communications Framework on sf_uart_comms
SCI Common
の3つのモジュールをスレッドに追加します。
SCI CommonのプロパティでUARTを有効にします。
UART Driverのプロパティに通信設定を行います。
コードジェネレートしてコンパイル通りました。
インスタンスはできているのでAPIを呼び出すと案外簡単にループバックが完成しました。
/* UART Thread entry function */
void uart_thread_entry(void)
{
/* TODO: add your own code here */
// Creates a variable for the error
ssp_err_t ssp_err_g_sf_comms;
// Creates a destination buffer
uint8_t dest_buffer[16];
while (1)
{
// Reads 16bytes from the SCI channel5 as an UART port.
// Wait until your callback funtion is called from SCI ISR.
ssp_err_g_sf_comms = g_sf_comms.p_api->read(g_sf_comms.p_ctrl, dest_buffer, 1, 100);
if (SSP_SUCCESS == ssp_err_g_sf_comms)
{
// Writes 16bytes to the SCI channel5 as an UART port.
ssp_err_g_sf_comms = g_sf_comms.p_api->write(g_sf_comms.p_ctrl, dest_buffer, 1, 100);
}
}
}