Hi all, I need to send and receive (sending is the most critical, receive can be done at other rates/parity modes) serial data in 8-bit, odd parity, 9600bps from a BX24, has anyone got any bit-bashed routines for doing this? I've been searching around, but found nothing useful. Regards, Mike |
|
Sending serial data at 9600 8O1?
Started by ●May 22, 2004
Reply by ●May 22, 20042004-05-22
--- In , "Michael Puchol" <mpuchol@s...> wrote: > I need to send and receive (sending is the most critical, > receive can be done at other rates/parity modes) serial data in > 8-bit, odd parity, 9600bps from a BX24, has anyone got any bit- > bashed routines for doing this? I've been searching around, but > found nothing useful. I don't think that you can write a routine in BasicX that will shift out the bits at the right speed at this baud. There are two factors that may affect the ability go get the timing right. One is the instruction execution speed of BasicX and the second is that fact that, at a minimum, you have the RTC interrupt being serviced which takes time away from your code. The timing of the bit slots is critical because the receiver will be sampling each bit at what it thinks is the center of the slot. It is more likely that you could write code that works at a slower speed, say, 2400 or 1200 baud. It may be possible to use OutputCapture() to produce the right waveform. At least you could get the timing a lot closer to what you need. I would guess that the throughput (character rate) would be quite slow due to the overhead of computing the proper high and low times. When I ran the code below (configured for 19.2K baud), I saw a waveform on the scope that looked OK except for a glitch about 800us before the start bit. I suppose that that might be an artifact of the way that the output capture is implemented. Public Sub Main() Dim bits(1 to 9) as Integer ' load pulse information for the character code &H35 bits(1) = 386 ' start bit bits(2) = 386 ' bit 0 high bits(3) = 386 ' bit 1 low bits(4) = 386 ' bit 2 high bits(5) = 386 ' bit 3 low bits(6) = 772 ' bits 4 and 5 high bits(7) = 772 ' bits 6 and 7 low bits(8) = 386 ' start bit Do Call OutputCapture(bits, 7, 0) Call Delay(0.001) Loop End Sub |
Reply by ●May 22, 20042004-05-22
Hi Don, Thanks for your input! I'll give that a wirl - I know some people have done this in ASM on PICs, but we're on a different world here. I was afraid of the timer taking it's toll on the output, the problem is that this has to go out at 9600 (Nokia MBUS protocol). Best regards, Mike ----- Original Message ----- From: "Don Kinzer" <> To: <> Sent: Saturday, May 22, 2004 10:27 PM Subject: [BasicX] Re: Sending serial data at 9600 8O1? > --- In , "Michael Puchol" <mpuchol@s...> wrote: > > I need to send and receive (sending is the most critical, > > receive can be done at other rates/parity modes) serial data in > > 8-bit, odd parity, 9600bps from a BX24, has anyone got any bit- > > bashed routines for doing this? I've been searching around, but > > found nothing useful. > > I don't think that you can write a routine in BasicX that will shift > out the bits at the right speed at this baud. There are two factors > that may affect the ability go get the timing right. One is the > instruction execution speed of BasicX and the second is that fact > that, at a minimum, you have the RTC interrupt being serviced which > takes time away from your code. The timing of the bit slots is > critical because the receiver will be sampling each bit at what it > thinks is the center of the slot. It is more likely that you could > write code that works at a slower speed, say, 2400 or 1200 baud. > > It may be possible to use OutputCapture() to produce the right > waveform. At least you could get the timing a lot closer to what you > need. I would guess that the throughput (character rate) would be > quite slow due to the overhead of computing the proper high and low > times. > > When I ran the code below (configured for 19.2K baud), I saw a > waveform on the scope that looked OK except for a glitch about 800us > before the start bit. I suppose that that might be an artifact of > the way that the output capture is implemented. > > Public Sub Main() > Dim bits(1 to 9) as Integer > > ' load pulse information for the character code &H35 > bits(1) = 386 ' start bit > bits(2) = 386 ' bit 0 high > bits(3) = 386 ' bit 1 low > bits(4) = 386 ' bit 2 high > bits(5) = 386 ' bit 3 low > bits(6) = 772 ' bits 4 and 5 high > bits(7) = 772 ' bits 6 and 7 low > bits(8) = 386 ' start bit > > Do > Call OutputCapture(bits, 7, 0) > Call Delay(0.001) > Loop > End Sub > Yahoo! Groups Links > |
Reply by ●May 23, 20042004-05-23
--- In , "Michael Puchol" <mpuchol@s...> wrote: > I need to send and receive (sending is the most critical, > receive can be done at other rates/parity modes) serial data in > 8-bit, odd parity, 9600bps from a BX24, has anyone got any bit- > bashed routines for doing this? I've been searching around, but > found nothing useful. I may want to use 801 myself. I remember reading that the UART on the BX-24 is 11 bit. I set up a project that set the UART to 11 bit and did 8N2. It worked fine. From there all one would need to do is force the parity bit depending on the requirements either by a formula or lookup table. The only other trick is that you would need to make sure you were setting the parity on the actual byte being sent. I never went any further with it but I'm sure it can be done. As far as calling a lookup table on every byte being sent, I do that now for calculating CRC16 with almost no delay between bytes. Here is a clip of that old code. I believe my comments tell the story: 'bit 2 sets UART to 9 bit data 'bit 0 forces 9th bit on to act as 1st stop bit Register.UCR = Register.UCR Or bx00000101 All one would need to do is force bit 0 of the register before sending the byte and don't send the next byte until the output queue is empty. I would try the following if I had time. (Gotta finish what I doing now and get ready to get on the road at 4AM!) Populate an array called TheBytes() and send it out Com1 as follows: (there could be bugs). You will need to create a lookup table. Each element of the table would have a 1 or 0 for the parity. I make my tables with 2 columns of 128 when working with bytes. I'm sure someone here could write a small app for generating parity tables... For I = 1 To NumBytes Parity = ParityOdd_Table((TheByte(I) \ 128) + 1, (TheByte(I) Mod 128) + 1) 'get parity from a lookup table. Anyone know how to generate it from a small formula? Register.UCR = Register.UCR Or Parity 'Set the bit Call PutQueue(Com1Out, TheByte(I), 1) ' Send the byte Do While StatusQueue(OutputQueue) ' Wait for the queue to empty Loop Do Until ((Register.USR And TXC) = TXC) 'Wait for the UART to empty Loop Next If this test worked, I would make this code into a sub routine and get rid of the For-Next loop and the array. You would only need to pass in the byte being sent. If someone makes this work, let me know. Thanks! BTW, I wonder if NetMedia could add parity to the BX functions??? Brad |