modify pic32mz usart library in 9bits transmitter

Author
月半弯
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2016/05/15 19:52:35
  • Location: 0
  • Status: offline
2016/05/19 18:41:36 (permalink)
0

modify pic32mz usart library in 9bits transmitter

在使用库函数PLIB_USART_Transmitter9BitsSend(USART_MODULE_ID index, int8_t data, bool Bit9th)进行9位模式发送数据时,若参数data的bit7位为1,即使Bit9th的值为false,但TX引脚上观测到的时序显示bit9位为1,而且接收端也确实接收到该地址位为1。将形参data对应的实参数据类型定义为unsigned char 或signed char ,问题依然存在;经过单步运行未发现程序逻辑存在问题。
为了解决问题,索性直接修改了其调用函数
PLIB_TEMPLATE void USART_Transmitter9BitsSend_InDataOnly( USART_MODULE_ID index , int8_t data , bool Bit9th )
{
    SFR_TYPE temp;
        if (Bit9th == 0)
        {
                    //_SFR_WRITE(_USART_TRANSMITTER_DATA_ONLY_VREG(index),        data);
        temp = data;
                    temp = temp&0x0ff;
                    _SFR_WRITE(_USART_TRANSMITTER_DATA_ONLY_VREG(index),temp);
        }
        else
        {
                    temp = data;
                    temp = (temp|(Bit9th<<8));
                    _SFR_WRITE(_USART_TRANSMITTER_DATA_ONLY_VREG(index),temp);
        }
}
经上述修改后问题得到解决。因不太清楚该芯片的汇编指令,未查看原库函数编译后的汇编代码。
#1

1 Reply Related Threads

    ric
    Super Member
    • Total Posts : 22101
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: modify pic32mz usart library in 9bits transmitter 2016/05/19 21:41:12 (permalink)
    4 (1)
    Google translated

    When using the library function PLIB_USART_Transmitter9BitsSend (USART_MODULE_ID index, int8_t data, bool Bit9th) were 9-bit mode to send data, if the parameter data of bit7 bit is 1, even Bit9th value false, but observed on the TX pin timing display bit9 bit is 1, and the receiver indeed receives the address bit is 1. The parameter data corresponding real parameter data type is defined as unsigned char or signed char, the problem still exists; No single step through the program logic problems.
    To solve the problem, simply call the function directly modify its
    PLIB_TEMPLATE void USART_Transmitter9BitsSend_InDataOnly (USART_MODULE_ID index, int8_t data, bool Bit9th)
    {
        SFR_TYPE temp;
            if (Bit9th == 0)
            {
                        // _ SFR_WRITE (_USART_TRANSMITTER_DATA_ONLY_VREG (index), data);
            temp = data;
                        temp = temp & 0x0ff;
                        _SFR_WRITE (_USART_TRANSMITTER_DATA_ONLY_VREG (Index), temp);
            }
            else
            {
                        temp = data;
                        temp = (temp | (Bit9th << 8));
                        _SFR_WRITE (_USART_TRANSMITTER_DATA_ONLY_VREG (Index), temp);
            }
    }
    The issue is resolved after the above modifications. Because the chip is not clear assembly instructions, did not see the original library functions compiled assembly code.

     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5