Hello together,
I need some help. I want to implement RS232 Uart with the following parameter into my project:
Baudrate: 100,000 should be possible via the custom setting in the RSR232 Setup Page
Start bit will be done by the PIC UART
8 data Bits as usual used for TX/RX no problem with that
Parity Bit: with even parity; (numbers of"1" in the 8 data bits; even:0 , odd:1 This is the first problem!! Maybe there is a way to use the 9Bit function in the RS232 Setup
2 Stop bits This is my second problem
ANY SUGGESTIONS ON HOW TO SOLVE PROBLEM ONE AND TWO??
PIC is 18f2420 with x-tal of 20Mhz
BR
Dirk
RS232 with parity and 2 stop bits
Moderator: Benj
-
- Posts: 99
- Joined: Fri Feb 02, 2007 3:54 pm
- Location: Germany
- Has thanked: 14 times
- Been thanked: 12 times
- Contact:
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: RS232 with parity and 2 stop bits
Hello Dirk,
Flowcode v4 and v5 for PICs supports 9-bit data mode for sending and receiving 9-bits through the UART. This extra bit could easily be used for parity. The 9-th bit is enabled through the RS232 component properties window.
A stop bit is simply a logic 1 on the bus for the length of a single bit period. As a logic 1 is the default bus state you could simply use the code customisation feature in flowcode to add a delay of 10us to the end of the send byte RS232 component macro to ensure that the second stop bit has enough time to be transmitted before sending the next byte or 9-bit packet. The second stop bit poses no problems to receiving data.
Flowcode v4 and v5 for PICs supports 9-bit data mode for sending and receiving 9-bits through the UART. This extra bit could easily be used for parity. The 9-th bit is enabled through the RS232 component properties window.
A stop bit is simply a logic 1 on the bus for the length of a single bit period. As a logic 1 is the default bus state you could simply use the code customisation feature in flowcode to add a delay of 10us to the end of the send byte RS232 component macro to ensure that the second stop bit has enough time to be transmitted before sending the next byte or 9-bit packet. The second stop bit poses no problems to receiving data.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 99
- Joined: Fri Feb 02, 2007 3:54 pm
- Location: Germany
- Has thanked: 14 times
- Been thanked: 12 times
- Contact:
Re: RS232 with parity and 2 stop bits
Hi Benj,
many thanks for the fast reply.
Yes i will try the 9Bit mode with putting in the parity bit as Bit9. That sounds great.
Since I don`t have a high knowledge regarding C-Code. Do you have a example how to edit the delay/transmit part of the custom RS232 component?
BR
Dirk
many thanks for the fast reply.
Yes i will try the 9Bit mode with putting in the parity bit as Bit9. That sounds great.
Since I don`t have a high knowledge regarding C-Code. Do you have a example how to edit the delay/transmit part of the custom RS232 component?
BR
Dirk
-
- Posts: 99
- Joined: Fri Feb 02, 2007 3:54 pm
- Location: Germany
- Has thanked: 14 times
- Been thanked: 12 times
- Contact:
Re: RS232 with parity and 2 stop bits
Hello Ben,
Hello together,
i`m still struggling with the 9th bit in the RS232 component to sent it as calculated 0 or 1 for parity information.
Let´s assume i want to sent EVEN parity and i will calculate the "ONES" in a byte.
If I have 4 ONES in the byte, the parity bit-9 must be 0!! Right?
With 5 Ones in the byte, the parity bit-9 must be 1!! Right?
So far so good. But how can I get this information out of the byte and set bit number 9??
Any help is highly aprecheated.
BR
Dirk
Hello together,
i`m still struggling with the 9th bit in the RS232 component to sent it as calculated 0 or 1 for parity information.
Let´s assume i want to sent EVEN parity and i will calculate the "ONES" in a byte.
If I have 4 ONES in the byte, the parity bit-9 must be 0!! Right?
With 5 Ones in the byte, the parity bit-9 must be 1!! Right?
So far so good. But how can I get this information out of the byte and set bit number 9??
Any help is highly aprecheated.
BR
Dirk
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: RS232 with parity and 2 stop bits
Hi Dirk,
For calculating the parity of a byte you could do something like this.
calculation: parity = 0
decision: data & 0x01
yes: calculation: parity = (parity + 1) & 0x01
decision: data & 0x02
yes: calculation: parity = (parity + 1) & 0x01
decision: data & 0x04
yes: calculation: parity = (parity + 1) & 0x01
decision: data & 0x08
yes: calculation: parity = (parity + 1) & 0x01
decision: data & 0x10
yes: calculation: parity = (parity + 1) & 0x01
decision: data & 0x20
yes: calculation: parity = (parity + 1) & 0x01
decision: data & 0x40
yes: calculation: parity = (parity + 1) & 0x01
decision: data & 0x80
yes: calculation: parity = (parity + 1) & 0x01
Then say your data variable is of type INT or 16-bit.
To write to the 9th bit you would do this.
calculation: data = (data & 0xFF) | (parity << 8 )
To read the 9th bit you would do this.
calculation: parity = (data >> 8 ) & 0x01
Hope this helps.
For calculating the parity of a byte you could do something like this.
calculation: parity = 0
decision: data & 0x01
yes: calculation: parity = (parity + 1) & 0x01
decision: data & 0x02
yes: calculation: parity = (parity + 1) & 0x01
decision: data & 0x04
yes: calculation: parity = (parity + 1) & 0x01
decision: data & 0x08
yes: calculation: parity = (parity + 1) & 0x01
decision: data & 0x10
yes: calculation: parity = (parity + 1) & 0x01
decision: data & 0x20
yes: calculation: parity = (parity + 1) & 0x01
decision: data & 0x40
yes: calculation: parity = (parity + 1) & 0x01
decision: data & 0x80
yes: calculation: parity = (parity + 1) & 0x01
Then say your data variable is of type INT or 16-bit.
To write to the 9th bit you would do this.
calculation: data = (data & 0xFF) | (parity << 8 )
To read the 9th bit you would do this.
calculation: parity = (data >> 8 ) & 0x01
Hope this helps.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 99
- Joined: Fri Feb 02, 2007 3:54 pm
- Location: Germany
- Has thanked: 14 times
- Been thanked: 12 times
- Contact:
Re: RS232 with parity and 2 stop bits
Hi Ben,
your solution works perfect in simulation!! Great many thanks for your help!!
BR
Dirk
your solution works perfect in simulation!! Great many thanks for your help!!
BR
Dirk
- JonnyW
- Posts: 1230
- Joined: Fri Oct 29, 2010 9:13 am
- Location: Matrix Multimedia Ltd
- Has thanked: 63 times
- Been thanked: 290 times
- Contact:
Re: RS232 with parity and 2 stop bits
Hello Dirk. Just to add to what Ben posted, you can also find the parity in a single calculation box if you like:
The result is the same: 1 for odd, 0 for even. This is only really necessary if your code needs to process the data faster.
Cheers,
Jonny
Code: Select all
parity = (data) - ((data >> 1) & 0x55)
parity = (parity & 0x33) + ((parity & 0xCC) >> 2)
parity = (parity + (parity >> 4)) & 0x1
Cheers,
Jonny
-
- Posts: 99
- Joined: Fri Feb 02, 2007 3:54 pm
- Location: Germany
- Has thanked: 14 times
- Been thanked: 12 times
- Contact:
Re: RS232 with parity and 2 stop bits
Hi Jonny,
great idea and very good support! I will try your solution too.
In two weeks i will check out both solutions on hardware.
Many thanks!!
BR
Dirk
great idea and very good support! I will try your solution too.
In two weeks i will check out both solutions on hardware.
Many thanks!!
BR
Dirk