PDA

View Full Version : Pass on serial data



The Master
- 12th June 2007, 20:23
Hi, hopefully a simple one this time. i want my chips to startup and wait for a serial command. the serial data is (250),lineid then a string of bytes. the chip needs to send out the whole string on another pin but add 1 to the lineid. my code so far is this.



serin2 porta.2,n9600,[WAIT(250),lineid,str tinput\8\0]
lineid=lineid+1
serout2 portb.4,n9600,[250,lineid,str tinput\8]


this works fine aslong as i send 8 bytes after the line id. is there a way i can make it wait for 250 and the lineID then take whatever it can after that and pass it on?

the chips will be linked to each other but they dont know how many chips there are and the string of bytes is (4 * number of chips) long

also, how do i tell how many characters came in? is there a len() function like VB or ubound()? if not then i know a way i can work round it

skimask
- 12th June 2007, 20:32
If you get 8 characters, you send them off...

If you get 5 characters, how do you know that's all you're going to get?
Is it a timed thing? Is the 5th character a CR or LF or something that would be recognizable?

The Master
- 12th June 2007, 20:43
If you get 8 characters, you send them off...

If you get 5 characters, how do you know that's all you're going to get?
Is it a timed thing? Is the 5th character a CR or LF or something that would be recognizable?

hmm. good point. i can make it so theres only 2 characters per chip and i can send something like (255) to show the end of the data.

that means the chip reacts to [250],lineid,[1],[2],[3],[4],[255] AND [250],lineid,[1],[255]. how would i do that?

mister_e
- 12th June 2007, 20:50
I could analyse the STR macro, but i'm lazy today :D

So you could still fill ALL variable array cells with zero before SERIN, and after SERIN checking which one is still = 0.

The Master
- 12th June 2007, 20:53
yep. thats my workaround way :P i wont have to check them after though, just set them to the correct outputs

mister_e
- 12th June 2007, 21:27
One thing i could feel... the internal R0 variable should store the last character. Seems there's no counter variable. For that i would prefer to build my own routine BUT using the PIC USART... no SERIN/DEBUGIN/HSERIN at all.

The Master
- 12th June 2007, 21:33
One thing i could feel... the internal R0 variable should store the last character. Seems there's no counter variable. For that i would prefer to build my own routine BUT using the PIC USART... no SERIN/DEBUGIN/HSERIN at all.

ill have a look into that later. isnt there a way of doing it with serin2? eventually i will need to use the timeout things too

mister_e
- 12th June 2007, 21:37
If your PIC have a USART and you need only 1 SerialInput pin, there's no advantage to use SERIN, SERIN2, DEBUGIN. Even if you need only 1 SerialInput pin, there's no real advantage to not choosing a PIC without USART.

With a built-in USART, the whole thing could be hapilly managed with interrupts, which it's not really reliable with SERIN... unless you send tons of 'preamble' NULL character or so.

Yeah, i'm from an old school ;)

The Master
- 12th June 2007, 21:44
i cant do anything with interrupts. ive already made the PCBs up for these circuits and the only interrupt pin is an output. i never thought i would need it

mister_e
- 12th June 2007, 21:50
can you post your schematic?

The Master
- 12th June 2007, 22:01
can you post your schematic?

sure, here it is.


i spoke with a really clever electronics guy today about that capacitor thing mentioned in the last thread. he showed me the best way to do it but its not done in this circuit obviously.

the only interrupt pin is RB0 which is the 4th pin up on the left and thats in use on the first triac optoisolator


Edit: aparently the bmp is too big. sorry for the jpeg quality

mister_e
- 12th June 2007, 22:06
:eek: no i meant a real schematic, not a board layout :(

The Master
- 12th June 2007, 22:11
:eek: no i meant a real schematic, not a board layout :(

oh, erm. i havnt got one. sorry

mister_e
- 12th June 2007, 22:16
mm, so you could move what's on RC7 to RC5, and free BOTH USART pin? yeah some PCB mods... no harm, but bit of pain i agree..

The Master
- 12th June 2007, 22:20
mm, so you could move what's on RC7 to RC5, and free BOTH USART pin? yeah some PCB mods... no harm, but bit of pain i agree..

i could but as i said ive already etched the PCBs as i didnt have any need to use the interrupt pin. any new circuits i do ill always use the interrupt pin as the serial input.

suppose if theres no other way to do it then i can just write my VB app to always send out so many characters

mister_e
- 12th June 2007, 22:23
Maybe not impossible... still doable... just longer... let's see how your tests will go!