PDA

View Full Version : 16F88 7 data bits



rwskinner
- 12th February 2008, 03:04
I have to set up for 9600, 7,N,1 and I do see the defines in PBP :
Define SER_BITS 7 But I need to be able to do it during runtime.

I don't understand how to do it using the 16F88 Datasheet.
I know how to do the Baud Rate during runtime as I've done that many times.

Richard

skimask
- 12th February 2008, 04:52
I have to set up for 9600, 7,N,1 and I do see the defines in PBP :
Define SER_BITS 7 But I need to be able to do it during runtime.

I don't understand how to do it using the 16F88 Datasheet.
I know how to do the Baud Rate during runtime as I've done that many times.

Richard

Are you saying that you have to switch back and forth between 8N1 and 7N1?
Short of writing your own serial routines, I don't see it happening with PBP.

A thought (if in fact it's not possible to switch between 7N1 and 8N1), how about putting a 'hijacking' PIC in between the receiving PIC and the sending device to receive 7N1 in software and send out 8N1 in hardware....a sort of buffering translator...I can see a 16F628A doing that rather easily.

paul borgmeier
- 12th February 2008, 05:09
>>Define SER_BITS 7

I think you mean DEFINE SER2_BITS 7 and this is for software Serial Out (not Hardware) so the data sheet will not help in this case. The hardware UART (on all PICs?) does not support 7N1.

Something to try: two adjacent pins connected together ... set one for output using SEROUT 8N1. Set the adjacent pin for output using SEROUT2 7N1. Make the pin not in use an input - switch back and forth as needed. You also could use the USART for the 8N1 rather than SEROUT. You might need weak pullups (or pulldowns if inverted mode) to ensure the serial line is not corrupted when you switch between pins.

Good Luck

skimask
- 12th February 2008, 05:13
>>Define SER_BITS 7

I think you mean DEFINE SER2_BITS 7 and this is for software Serial Out (not Hardware) so the data sheet will not help in this case. The hardware UART (on all PICs?) does not support 7N1.

Something to try: two adjacent pins connected together ... set one for output using SEROUT 8N1. Set the adjacent pin for output using SEROUT2 7N1. Make the pin not in use an input - switch back and forth as needed. You also could use the USART for the 8N1 rather than SEROUT. You might need weak pullups (or pulldowns if inverted mode) to ensure the serial line is not corrupted when you switch between pins.

Good Luck

I thought the DEFINE for SERIN/SEROUT stuck constant for the whole program...like you can't re-DEFINE it.

paul borgmeier
- 12th February 2008, 05:23
I thought the DEFINE for SERIN/SEROUT stuck constant for the whole program...like you can't re-DEFINE it.

They do - that is why I suggested using SEROUT for one and SEROUT2 for the other. They are not related by the defines :)

rwskinner
- 12th February 2008, 05:26
Yes, two protocols jumper selectable. When I power up, I check the jumper then use the proper protocol. Modbus ASCII 9600,N,7,1 or Modbus RTU 9600,N,8,1. The device needs to be changed on the fly depending on the equipment it's being hooked to.

I know my CCS Compiler allows these settings but the project is an existing PBP project. I hate to have to convert it all.


Are you saying that you have to switch back and forth between 8N1 and 7N1?
.

skimask
- 12th February 2008, 05:27
They do - that is why I suggested using SEROUT for one and SEROUT2 for the other. They are not related by the defines :)

AHA! Missed that!

rwskinner
- 12th February 2008, 05:31
In the software serial routines, MELabs must be looking at the settings in order to determine how to send the data bits and set the parity right? Problem is it's a define and not a variable or it most likely could be changed on the fly.

I sure hate to bit bang this but I may have to.

Richard

paul borgmeier
- 12th February 2008, 05:41
>>I sure hate to bit bang this but I may have to.

you do not have to, PBP has done the work for you.

>>two adjacent pins connected together

another thought - no need for adjacent pins - use SEROUT for 8N1 and SEROUT2 for 7N1 ... using the same output port pin.

If PORTA.1 = 1 then ; check jumper
SEROUT PORTB.0, .... ; need 8N1
else
SEROUT2 PORTB.0, ... ; need 7N1
ENDIF

will that work?

Also, I do not see why you keep mentioning CCS??? We are taking PBP here

rwskinner
- 12th February 2008, 12:08
I'll give it a shot this morning. It "should" work.

Why do I keep mentioning CCS? I only mentioned it once in an effort to show it is possible to do it But upon closer examination, it also only handles it in software only.


>>>>two adjacent pins connected together
another thought - no need for adjacent pins - use SEROUT for 8N1 and SEROUT2 for 7N1 ... using the same output port pin.

Also, I do not see why you keep mentioning CCS??? We are taking PBP here

paul borgmeier
- 12th February 2008, 13:45
Hi Richard,

I hope this approach works for you.

Best of the Day,

rwskinner
- 12th February 2008, 17:00
Hi Richard,
I this approach works for you.
Best of the Day,

I ended up using SER2 for the 7,N,1 Stuff then
using HSER for the 8,N,1 Stuff.

Check the Dip switch, Configure TXSTA, RCSTA, SPBRG to the values needed or Zero if not needed. This worked great and allowed me to still use the modifiers like in SER2.

Thanks for the ideas.

Richard

rwskinner
- 17th February 2008, 01:05
Would it be possible to use the pic's hardware USART set at 9600,8,N,1 and receive and transmit data to the 7,N,1 device by simply massaging the bits some.

When I receive the bytes, I would shift them to the left once and store just the 7 bit value as a byte.

Before sending the bytes from the array, then make sure the 8th bit is a 1. Wouldn't the 7,N,1 system see this as 7 data bits and two stop bits?