how can i receive 8 bits in parallel to convert them to serial

paco556

New Member
Hi;
I am new in picaxe world, is there a way to catch 8 bits in parallel form and send them to serial port, how the program looks like, parallel data needs to be saved? Have a lot questions, if possible, show me what kind of picaxe micro I should use and how the program looks like?
Once parallel data is received, can it be send immediate through serial port, if possible, parallel data received is not needed to be save, as you see I still can not get the picture. I know once received (parallel data) some how needs to be saved in some place until it is send to serial port
Thanks in advance any help will be appreciated
New be trying to understand picaxes.
F.H.
 

hippy

Technical Support
Staff member
You can read parallel data using "b0 = pinsC" and similar, that will read up to 8 input signals at a time, depending on PICAXE and I/O port used.

You will probably want to use another signal to indicate when the input signal should be captured, such as when a pin goes high, and once captured you can then send that out serially, for example ...

Code:
Do
  Do : Loop Until pinB.1 = 1
  b0 = pinsC
  SerOut B.0, N1200_4, (b0)
  Do : Loop Until pinB.1 = 0
Loop
In this case you could even combine the "b0 = pinsC : SerOut B.0, N1200_4, (b0)" and just use "SerOut B.0, N1200_4, (pinsC)".

You can probably tailor that to suit what you want to do. The best PICAXE to use may depend on how quickly you need to transfer data, and you may need a slightly different approach if data is arriving quickly.

If you can tell us more about the application, what project you are attempting to undertake, it will be easier to provide more specific advice.
 

AllyCat

Senior Member
Hi,

It's easier if you use a PICaxe with a "full-width" port, e.g. 18M2, 20M2 or any of the X2s, but also possible with the 14M2. Then it's very easy with a PICaxe and could even be done in one line of code: SERTXD(#pinsB) which will print out the B-port value in decimal format on the Program Editor Terminal. ;)

But some explanation: pinsB is a variable which reads the B port, for which you need to see Manual 1 and 2 or perhaps the LET command in the on-line reference. Normally it would be assigned to a variable such as b0 = pinsB. SERTXD is a special command to use with the terminal emulator, but more normally one might use a SEROUT pin,baudmode,(#b0) command as described in the manuals or the on-line reference. You can also read/print the individual bits of b0 as bit0, bit1, etc. The # is used to print decimal digits and not the "raw" ASCII code byte.

The "simulator" in the Programme Editor is very useful for testing commands like these. Then personally I prefer the 20M2 as a starting point, because it is then very easy to convert the hardware "down to" a 14M2 or 08M2 or "up to" a 20X2.

Cheers, Alan.

PS: Again, hippy is faster at typing than me.
 
Last edited:

paco556

New Member
thanks for helping, think data is in hex form from in the parallel data.
what about serial data? if i want for example receive a 57600 baud rate and send a more slow baud rate let say 9600, can this be done by a picaxe micro how the program looks like? which picaxe micro needs to be used?
There is pair vintage devices that needs data be get one is serial (57600 baud rate) and other is parallel, can not see data of devices but a friend got a dso, in the serial one, and baud rate could be found, the other one has a centronic parallel port I am assuming is parallel, with the programming sample I am going to try, if possible, how serial program looks like to slow down baud rate? and give it a try reading data on an oled screen to learn more about picaxes, seems to me extremely interesting devices but I am a new be
 
Last edited:

eggdweather

Senior Member
Receiving at 57600 and sending at 9600 is relatively easy, set your IN and OUT speeds accordingly, however the nature of your data will determine if additional programming measures are required. For example if you receive data every 10-secs and re-send (at 9600) then there will not be a problem, but when the reception speed (at the 57600 port) becomes too high then you will not be able to re-send the data fast enough as the input rate is 6x faster than the output.

A typical solution would be to programme a First In First Out buffer (FIFO) which can become complicated and lends itself to a pointer solution (using the @BPTR functions) IMO.

How fast is your input data? If it is always faster than 9600baud (1 data byte per ~1mS (1/9600/(10-bits)) then you can't solve the problem without data loss, in-which case you should consider sampling the input to get the effective rate down to 9600baud.

If implementing a buffer solution you would need to set some limits that will be determined by the PICAXE device your using, typically a page of A4 paper can hold 3000 characters so that would need to be your approximate buffer size, but statistics is on your side as the speed of a printer is usually slower than 57600 baud and if it has an Centronic port (150kbps or 15 characters per second), then 57600 which is 5760 characters per second is much faster and your 9600 baud (speed determining port) can send data at 960 characters per second and so will always be faster than Centronics (assuming it's a standard port). SO now your buffer size probably needs to be much smaller, perhaps a single line of text to smooth out printer speed variations.
 
Last edited:

hippy

Technical Support
Staff member
The challenge for converting 57600 serial to 9600 serial is how quickly the incoming data arrives and how much of it there is, what format it is in, and what else one wants the program doing alongside serial conversion.

It is essential to not miss data arriving and that could happen when sending at 9600 using bit-banged SEROUT. The 28X2 does have a second UART which can probably be accessed via PEEKSFR/POKESFR so I would suggest that as the starting point. One can use background serial receive to take in the data and then it's a case of just taking data from the buffer and putting it out. Something like ...

Code:
HSerSetup B57600_64, %000
Gosub SetupUart2
Do
  Do : Loop While ptr = hSerPtr
  Do
     PeekSfr ?, b0
  Loop Until bit? = ?
  PokeSfr ?, @ptrInc
Loop
 

paco556

New Member
the device has a button that helps you to bring the next data bite as you wish, I think for write down data in case a printer is not available, there is like a serial port allowing you to set a printer or display device of some kind.
My idea is try to send data to a an oled screen, and then go from there, if possible for the oled screen manage the 57600 baud rate, picaxe micro can handle this?, let say, receive data at 57600 send it by the button and receive data, how the program looks like and what picaxe i need to use in order to catch data and resend again to oled screen, maybe this is easier, I am starting getting the idea what picaxes can do but still programming does not pop an my head.
Thanks for your help, and patience, hope not get bore you, but I need to learn more on this and you guys are incredible good.
Again I can tell how help full this is being to me (hard headed) but I hope get there.
 

AllyCat

Senior Member
Hi,

if possible for the oled screen manage the 57600 baud rate, picaxe micro can handle this?, let say, receive data at 57600 send it by the button and receive data,
For 57600 baud you will probably need to use HSERIN and/or an X2 PICaxe running at 64 MHz, but "one character at a time" should be quite easy to program. Basically, the program may not need to be much more than a repeating DO ... LOOP containing a few instructions to read, maybe store, and write data bytes between the PICaxe's pins/ports and data memory.

Cheers, Alan.
 
Top