Uart RX API使用方式/ How to use UART Receiver API

公告

大中华汽车电子生态圈社区并入开发者社区- 更多资讯点击此

Tip / 登入 to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
chyi_4662656
Level 2
Level 2
5 replies posted First question asked First reply posted

嗨,大家好,我是一位PSOC4的新手,請教一個關於UART的問題。

問題敘述:

目前UART傳送與接收都需要處理16 Bytes的資料,所以我將UART Advanced Buffers size改成16Bytes

因為之前我都是使用外部中斷來處理RX的資料,但是當我改成16Byte後就不能用外部中斷了,請問有人能跟

我說明如何處理接收的程式嗎?

        若能協助的話,可以提供Sample Code 教育訓練的文件嗎?

0 点赞
1 解答
lock attach
Attachments are accessible only for community members.
LinglingG_46
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 10 questions asked

您好,

附件是我写的关于uart rx的中断,我在CY8C4245AXI-483的芯片上面测试过了。

根据你的描述,你是只需要UART RX中断。

在原帖中查看解决方案

0 点赞
8 回复数
LinglingG_46
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 10 questions asked

1:

因为缓存分为: 硬件缓存或者软件缓存。 硬件缓存称之为FIFO,软件缓存称之为Buffer。

外部中断只能应用于缓存为FIFO的情况。

但是如果你在组件里面配置了超过8字节,这个时候就会切换为缓存buffer,所以只能用内部中断,也就是Internal ISR。

2:

接受中断的 中断处理函数如下:

UART_SetCustomInterruptHandler(RxHandler);

Interrupt processing function:

CY_ISR(RxHandler)

{

    if (0u !=
(UART_GetRxInterruptSourceMasked()                                                                   &
UART_INTR_RX_NOT_EMPTY)) {

        while (UART_SpiUartGetRxBufferSize() !=
0) {

            uint8 dat = UART_UartGetChar();

            if (dat != 0) {

                UART_UartPutChar(dat);

            }

        }

    }

    UART_ClearRxInterruptSource(UART_INTR_RX_NOT_EMPTY);

}

Note:

Clear RX interrupt action should be done after all data in buffer has been read.

3: 希望的回复能对你有所帮助。




lock attach
Attachments are accessible only for community members.

謝謝您的協助,依照您的建議後可以正常接收資料,但仍有些問題。

1.目前的程式TX傳送資料時,都會進入 CY_ISR(RxHandler) 中斷處理程式內,但是我並沒有開啟TX的任何中斷, 請問您知道是什麼問題嗎?  (傳送的方式如附件)

2.下圖藍色波形為TX傳送的訊號,黃色波型為只要程式有進入Rx_Handler中斷則反向一次。

  startime--00000.jpg

0 点赞

我推測是因為 UART_INTR_TX_NOT_FULL 造成的,但不太確定,有人能幫助我解惑嗎?

推測1.試著用GPIO去觀察是那些中斷源造成

CY_ISR(RxHandler)

{

    if(0u != (UART_GetTxInterruptSourceMasked()&UART_INTR_TX_NOT_FULL))

    {

        RxHandler_Flg^=1;

if(RxHandler_Flg)   RxHandler_Output_Write(1);

else RxHandler_Output_Write(0);

    }

  

    if (0u !=(UART_GetRxInterruptSourceMasked()&UART_INTR_RX_NOT_EMPTY))

    {

      

        NotEmpty_Flg^=1;

        if(NotEmpty_Flg) NotEmpty_Output_Write(1);

else NotEmpty_Output_Write(0);

        uint8 dat = UART_UartGetByte();

        RX_Array[Rx_Cnt]=dat;

    if((++Rx_Cnt)>=16)  {Rx_Cnt=0;}

UART_SpiUartClearRxBuffer();

    }

UART_ClearRxInterruptSource(UART_INTR_RX_NOT_EMPTY);

}

推測2.DATASHEET 註明TX buffer size 大於 TX FIFO時,會將中斷模式設定為內部中斷,並且當資料由circular software buffer轉移到TX FIFO時會利用TX FIFO NOT FULL interrupt source來操作資料轉移的流程。

pastedImage_0.png

0 点赞
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

你好

Can this sample of mine be any help?

我的这个样本能帮上什么忙吗?

tty_utils a utility sample for CLI type program

moto

0 点赞

Thanks!

0 点赞
lock attach
Attachments are accessible only for community members.
LinglingG_46
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 10 questions asked

您好,

附件是我写的关于uart rx的中断,我在CY8C4245AXI-483的芯片上面测试过了。

根据你的描述,你是只需要UART RX中断。

0 点赞

您好,抱歉 因為最近比較忙,現在才有時間回覆自己的問題。

您說的沒錯,目前程式我只需要UART RX的中斷,但是我發現當TX傳送資料的過程,會進入

CY_ISR(RxHandler) 中斷處理程式,經由測試後我發現是UART_INTR_TX_NOT_FULL造成的,

但是並沒有開啟任何UART TX的中斷。

所以我想確認,這樣的情形是不是因為以下的原因,(The interrupt mode is automatically set to

the internal and the TX FIFO not full interrupt source is reserved to manage software buffer operation:

move data from the circular software buffer into the TX FIFO.)

也就是說當TX Buffer>TX FIFO的時候會產生以下情形:

1.UART中斷源會自動改為內部中斷,且禁止使用UART外部中斷。

2.TX FIFO not full會被用來管理softwaer buffer資料的位移,也就是將資料位移至 TX FIFO。

因此造成就算我沒開TX任何的中斷源,但是我在傳送資料時,仍會進入到CY_ISR(RxHandler) 中斷處理程式。

0 点赞
LinglingG_46
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 10 questions asked

UART是这样处理的。

1.UART中斷源會自動改為內部中斷,且禁止使用UART外部中斷。

2.TX FIFO not full會被用來管理softwaer buffer資料的位移,也就是將資料位移至 TX FIFO。

你在中断函数里面不要再用not full的tx中断了。 具体的RX的中断处理函数和工程,我已经在之前的回复中上传了。

0 点赞