• slider image 442
  • slider image 477
  • slider image 479
  • slider image 480
  • slider image 481
  • slider image 482
:::


Browsing this Thread:   1 Anonymous Users






Re: 接收LIN同步信號問題?
#2
資深會員
資深會員


查看用戶資訊
印象中UART遇到ERROR要CREN關閉再開,但這顆MCU沒有CREN有類似的機制嗎?

發表於: 2021/12/15 17:53
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


接收LIN同步信號問題?
#1
資深會員
資深會員


查看用戶資訊
MCU:dsPIC33EV64GM104
開發板:DM330018_Starter_Kit_Demo
我自己發送LIN的同步信號出去再送8個BYTE資料和checksum(每200ms送一次資料)
因為MCP2021A送出的資料自己也會收到,我試著用範例程式的做法等收到同步信號也就是產生FERR訊框錯錯時設定LIN_START=1準備開始收資料,但我卻發現_U1ErrInterrupt
一直被觸發但不是OERR,FERR,PERR 我用LED做測試,LED2會一直閃爍表示一直在中斷
但LED3卻沒亮...

到底是為什麼_U1ErrInterrupt一直被中斷 量了一下也是200ms被中斷一次,也就是說是收到同步信號才產生的中斷,我試著將同步信號取消(11BIT LO)_U1ErrInterrupt就不會被中斷了





void __attribute__((interrupt, no_auto_psv)) _U1ErrInterrupt(void)
{
if (U1STAbits.OERR == 1)
{
U1STAbits.OERR = 0;
LED3_SetHigh();
}

if (U1STAbits.PERR == 1)
{
U1STAbits.PERR = 0;
LED3_SetHigh();
}

if (U1STAbits.FERR == 1)
{
lin_start = 1; // first message detection phase
// U1STAbits.OERR = 0;
LED3_SetHigh();
}
LED2_Toggle();
IFS4bits.U1EIF = 0;
}

void LIN_Transmit(void)
{
// send break followed by 0x55 'autobaud' byte
while (U1STAbits.TRMT == 0); // wait for transmitter empty
while (U1STAbits.UTXBRK == 1); // wait for HW to clear the previous BREAK
U1STAbits.UTXEN = 1; // Enable UART TX
U1STAbits.UTXBRK = 1; // set the BREAK bit
U1TXREG = 0; // dummy write to trigger UART transmit
Nop(); // must wait 1 instruction cycle
U1TXREG = 0x55; // AUTO-BAUD sync character per J2602 spec

// send the LIN_MESSAGE_ID byte, is arbitrary but must be in the range 0x00 to 0x3B
// there are also 2 parity bits sent
LIN_ID = 0x23;
p0 = (LIN_ID & 0x01) ^ ((LIN_ID & 0x02) >> 1) ^ ((LIN_ID & 0x04) >> 2) ^ ((LIN_ID & 0x10) >> 4);
p0 = p0 & 0x01; // get bit value
p1 = ~(((LIN_ID & 0x02) >> 1) ^ ((LIN_ID & 0x08) >> 3) ^ ((LIN_ID & 0x10) >> 4) ^ ((LIN_ID & 0x20) >> 5));
p1 = p1 & 0x01; // get the bit value
id_byte = (p1 << 7) | (p0 << 6) | LIN_ID; // stuff parity bits into proper places

// form protected ID byte and transmit it
// the bit stuffing is optional, used here to test LIN receiver hardware
checksum = id_byte; // initial checksum value (limited to a byte value)
while (U1STAbits.TRMT == 0); // wait for transmitter empty
Nop();
U1TXREG = id_byte; // transmit the protected ID byte

//等SLAVE回資料

}

發表於: 2021/12/15 16:48
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------