본문 바로가기

Network Tech/소프트웨어

PL칩 패리티비트 사용방법 - 시리얼 통신

애쉴론의 PL3120/3150칩은 SCI 시리얼 통신을 지원합니다. 

일반적으로?는 보통 패리티비트를 사용하지 않지만 사용해야 하는경우 문제가 있습니다. 칩이 패리티비트를 지원하지 않기 때문입니다. FT5000이후의 칩인 경우 이를 지원하지만 이보다 앞서 출시된 칩의 경우 패리티 비트 설정을 지원하지 않습니다.

이럴 경우 직접 레지스터를 핸들링 하여 9번째 비트를 패리티비트로 사용하는 방법이 있습니다. 

Using polled I/O for SCI with 9th bit data access for parity

Declare an SCI I/O object with the “twostopbits” option: 9번째 비트 사용을 위해 twostopbits 옵션을 선언합니다.

twostopbits (참고)

Set this option to use two stop bits. By default, there is one stop bit.

You cannot use two stop bits if you also specify even or odd parity. That is, to

use two stop bits, you must specify __parity(none).

This keyword is not supported for Series 5000 devices.


IO_8 sci baud(SCI_19200) twostopbits ioSci;

 

Disable interrupts:

io_idis();

 

Perform polled I/O by accessing the SCI registers directly.

 

// Read & write data register

#define SCI_DATA_REG    *(unsigned short *)(0xFFA8)

 

// Control register

#define SCI_CNTRL_REG   *(unsigned short *)(0xFFA9)

// Bit fields for control register

#define SCIC_RX9              0x01    // RX 9th bit, read only

#define SCIC_SBRK             0x01    // Send break, write only

#define SCIC_TX9              0x02    // TX 9th bit

#define SCIC_RXFE             0x04    // RX framing error, read only

#define SCIC_RXNF             0x08    // RX noise flag, read only

#define SCIC_RXOR             0x10    // RX buffer overrun, read only

#define SCIC_IDLE             0x20    // RX idle (marking), read only

#define SCIC_RXFULL           0x40    // RX buffer full, read only

#define SCIC_TXBMT            0x80    // TX buffer empty, read only

// SCIC_RXFE, SCIC_RXNF, SCIC_RXOR and SCIC_IDLE are cleared

// by reading the SCI_DATA_REG.




 

For transmit, when the following is true: //전송

        (SCI_CNTRL_REG & SCIC_TXBMT)

 

first set the 9th bit data:

        SCI_CNTRL_REG = (data9) ? SCIC_TX9 : 0;

 

then set the 8 bit TX data register:

        SCI_DATA_REG = data8;

 

 

For receive, when the following is true: //수신

        (SCI_CNTRL_REG & SCIC_RXFULL)

 

first read the 9th bit data:

data9 = (SCI_CNTRL_REG & SCIC_RX9);


then read the 8 bit RX data register:

        data8 = SCI_DATA_REG;