Tip / ログイン to post questions, reply, level up, and achieve exciting badges. Know more

cross mob

PSoC®3でのprintf関数の使用 - KBA83472 - Community Translated (JA)

PSoC®3でのprintf関数の使用 - KBA83472 - Community Translated (JA)

SivaK_96
Employee
Employee
50 questions asked 10 questions asked 5 questions asked

Community Translated by NoTa_4591161         

Version: *B

Translation - English: Using the printf Function in PSoC® 3 - KBA83472

 

質問:

stdio.hprintf関数を使用してPSoC®3デバイスのUARTにデータを送信するにはどうすればよいでしょうか?

 

回答:

Keilprintf関数はputchar()を呼び出して文字を送信しますが、デフォルトのputchar()PSoC®3にはないUARTベースの特殊機能レジスタ(SFR)を使用します。したがって、printfを使用するには、プログラムでKeilの組み込みputchar関数をオーバーライドする必要があります。

たとえば、「UART」がプロジェクトのUARTコンポーネントのインスタンス名である場合、main.cファイルに次の関数を記述して、Keilの組み込みputchar関数をオーバーライドします。

char putchar(char c) {         UART_WriteTxData((uint8)c);         return c; }

次に、printfを使用して次の方法でUART経由でデータを送信できます(適切に実行するには、printf()関数を最初に呼び出す前にputchar()関数を定義または宣言する必要があります)。

int main()
{
        UART_Start();
        while(1)
        {
            printf(“Hello world”); // uses the new putchar() function to stream data over UART
            while(!(UART_ReadTxStatus() & UART_TX_STS_COMPLETE)); // wait until transfer is complete
        }
}

0 件の賞賛
284 件の閲覧回数