Switching issues

Rampz

Well-known member
Well, I worked in heavy industry for 30 years
Thank you MikeyBoo great to get some info from industry, seems i'm best using something like the RS232 converter chips like Phil says and only going 2m seems i hope i will be fine, if i manage 9600 baud then great, i don't understand Baud rate other than it being a transmission speed, like can you work out how long a byte will take to be sent etc?
 

papaof2

Senior Member
The EPEver solar charge controllers use RS485 to communicate with remote display meters or PC's. They list the cable length as 50 meters (164 feet) Definitely a good choice for longer distances.
I have seen RS232 used at 9600 baud for several hundred feet, using shielded cable in an electrically noisy environment (multi-floor electro-mechanical telephone office). Probably not to spec but it worked, in spite of enough difference in AC neutral potentials to get an arc on the ground connections when connectings things several floors apart :-( Those arcs led to some very expensive power re-work to eliminate that problem...
 

PhilHornby

Senior Member
I don't understand Baud rate other than it being a transmission speed, like can you work out how long a byte will take to be sent etc?
Wikipedia said:
"The term baud has sometimes incorrectly been used to mean bit rate,[3] since these rates are the same in old modems as well as in the simplest digital communication links using only one bit per symbol, such that binary digit "0" is represented by one symbol, and binary digit "1" by another symbol"
In practice, I think it's always misused to mean bit rate: I've never heard it used in any context other than 'the simplest digital communication links', i.e. serial comms. ;)

So if you reckon on 8 bits-per-character, 1 start bit and 1 stop bit, you get 10 bits-per-character. So 9600 baud is (effectively) the same as saying 960 characters/second.

I have seen RS232 used at 9600 baud for several hundred feet, using shielded cable in an electrically noisy environment (multi-floor electro-mechanical telephone office). Probably not to spec but it worked ...
But are you sure it was RS232 and not 20mA current-loop ?

20mA is what I saw used to great effect, in the depths of the factories and warehouses where I spent my first 18 years in IT. We hit a problem when DEC and Xerox developed Ethernet. DEC's later Ethernet Terminal Servers didn't do 20mA - only DEC423 (aka RS423). They said to just connect one signal to GND and the other to TX or RX as appropriate o_O. The results were hilarious - with the VDU/Printer or whatever switched off, the now floating line picked up all the interference possible and played havoc with the poor VAX at the other end of the link :(

I found that a 4.7K resistor to GND fixed that issue and DEC turned up on site and fitted them in their hundreds! I don't know if any of their other customers ever received my hardware fix :unsure:

I digress ;) ...
 

Rampz

Well-known member
Just want to check the Master / Slave set up using the scratchpad for background data now we have sorted the 2m data transmission

Each 20X2 Master will communicate on HSEROUT / HSERIN via RS232 to RS232 to the 28X2 Display Slave which will receive all data from all masters on the same HSEROUT and HSERIN pins?

With RS232 inbetween using a MAX3232 ic
 

PhilHornby

Senior Member
Each 20X2 Master will communicate on HSEROUT / HSERIN via RS232 to RS232 to the 28X2 Display Slave which will receive all data from all masters on the same HSEROUT and HSERIN pins?
Each of the inputs from the 'Masters' is a Picaxe output, so you'll need (at least) a diode mixer to multiplex the signals together. Inverted serial (i.e. normally LOW), with a single resistor to GND should do the trick. This is to protect the Picaxe outputs, should two of them transmit at the same time.

Speaking of transmitting at the same time: should this occur, the Master will be unaware of it. The Slave will see either gibberish or nothing at all. One way round this, is to alter the logic - with a single central Master, that polls the Slaves, one at a time.

EDIT: Thinking further, the addition of the RS-232-C to TTL converter might have a bearing - and might make it easier to multiplex the inputs together, at that point.
 

Rampz

Well-known member
EDIT: Thinking further, the addition of the RS-232-C to TTL converter might have a bearing - and might make it easier to multiplex the inputs together, at that point.
I don't see any issues at the Masters end, as each Master will have its own RS232 max3232, but at the slave display end not sure if the 3x RS232's will be connected together before the convertor (max3232) then after the convertor its just tx and rx, of if i have 3x max3232 with the TTL side linked together?

Will there be pullup resistors used on the TX and RX connections TTL side to the RS232 converter, and how to go about mixing signals with diodes?

With using a multicode cable between master and slave i will be able to have both TX and RX so i expect the Slaves can send a command to each Master asking for data to avoid problems?

Hippy did think originally there would be 3x masters talking to 1x display slave, but seems with RS232 it will now be the opposite with a display Master talking to 3x Slaves?

Maybe someone has a sketch of the connections for all this, getting rather confusing at the moment, Found this sketch, see mention of diodes and resistors etc

Attached the 3rd image is multidrop TTL

Edit
Found this:

The RS-232 driver (Maxim Part No. MAX242) can be tri-stated under software control. This allows standard point-to-point full duplex communications, as well as a multi-drop configuration with one master (a single QVGA Controller or a desktop computer) and multiple QVGA Controller slaves. To implement this multi-drop scheme, each slave keeps its RS-232 transmitter silent until it is addressed by the master and is given permission to transmit. The advantage of such a multi-drop RS-232 network is that the communications are full duplex, with each communicating party capable of simultaneous transmission and reception of data. The software routines, RS232Transmit() and RS232Silent() control the dual RS232 transmitters on the board.
 

Attachments

Last edited:

PhilHornby

Senior Member
Will there be pullup resistors used on the TX and RX connections TTL side to the RS232 converter, and how to go about mixing signals with diodes?
Note: the MAX232 datasheet show that the TTL/CMOS inputs are pulled-UP weakly via 400K and RS-232 inputs are pulled DOWN by 5K (the 4.7K resistor in my previous tale!)

I don't think trying to 'mix' the RS-232 signals is a good idea - since they may swing either side of 0V. As for mixing the TTL signals, that will presumably be influenced by the choice of 'normal' or 'inverted' serial data. (Use of inverted would allow an AXE027 to be used as a debugging tool across the line, which might be considered an advantage)
 

Rampz

Well-known member
I don't think trying to 'mix' the RS-232 signals is a good idea
Phil

That's fine, so maybe the SMMS_TTL pic above then with diodes? And a pair of RS232's per picaxe - picaxe connection is fine

I'm looking at the max3232 slightly different to the max232, seems the max3232 is lower power and while it has the 5k DOWN resistor, it doesn't look like it has the 400k pull-up

Looks like the RS232 link will invert the signal at one end and do the opposite at the other end, so i guess the result is ok?

Just need to get my head around what i am atually doing, all moving in a positve direction
 

Attachments

Last edited:

PhilHornby

Senior Member
so maybe the SMMS_TTL pic above then with diodes? And a pair of RS232's per picaxe - picaxe connection is fine
I think that would only work for a TTL link - not RS-232, with its ± voltages...


This is what I knocked up, for doing the mixing at the Master end :-
25259

(The inputs connect to the TTL outputs of a MAX232(2) at the Master. The output goes to HSERIN on the Picaxe 20X2. This implies THREE MAX2322's at the Master though!)

The presence of the internal 5K resistor, makes the "Normal - i.e. Idle HIGH, look the less attractive of the two (though it should work). Maybe I'm being pessimistic and R3 doesn't need to be that low a value, as in, if any MAX232 pulls its the Input LOW, the voltage drops to 0.6V. Um... :unsure:
 
Last edited:

Rampz

Well-known member
This implies THREE MAX2322's at the Master though!)
Yes i expected that and its fine, i have ordered 2x max3232's and the caps that the data sheet speaks about for the input voltage

You have the RS232 convertor as a MAX2322, i have it as a MAX3232 just checking?

(The inputs connect to the TTL outputs of a MAX232(2) at the Master. The output goes to HSERIN on the Picaxe 20X2.
After reading this multiple times, the diagram will fit at the output of the 3x MAX3232's and mix the signals to the HSERIN, which diodes you thinking, something like 1N4148 signal diodes?

The Master will be a 28X2 since its driving a screen

I assume therfore the HSEROUT of the 28X2 will just be tripled up without anything resistor of diode wise? Going to the Slaves HSERIN?
 

PhilHornby

Senior Member
You have the RS232 convertor as a MAX2322, I have it as a MAX3232 just checking?
Ignore me - finger's going faster than brain :)
After reading this multiple times, the diagram will fit at the output of the 3x MAX3232's and mix the signals to the HSERIN, which diodes you thinking, something like 1N4148 signal diodes?
Yes. (and I think virtually any diode will do.)
I assume therefore the HSEROUT of the 28X2 will just be tripled up without anything resistor of diode wise? Going to the Slaves HSERIN?
The conventional wisdom is to put a 1K resistor in series - I always forgot though (with no ill effects ... yet).
(For NORMAL comms) Maybe I'm being pessimistic and R3 doesn't need to be that low a value, as in, if any MAX232 pulls its the Input LOW, the voltage drops to 0.6V.
Thinking further - it needs to be low enough to produce a logic "1", in the absence of any input "0"s, so it probably does need to be 470R, or thereabouts.
 

Rampz

Well-known member
The conventional wisdom is to put a 1K resistor in series - I always forgot though (with no ill effects ... yet
Phil thank you, yep i had seen that, i will draw up how i see the connections before i start, its still confusing me, remembering tx to rx and rx to tx etc etc
 

hippy

Technical Support
Staff member
So how do you try and make sure all masters don't send at the same time when only using 1 wire?
Normally one would use some mechanism so a sender can request sole access to the bus, detect it is able to send, then release the bus when done. That's usually done by using three wires.

It should be possible to have a 1-wire bus for all that by making it multi-state; 0V/5V for signalling, 2.5V when the bus is free, monitor that bus with an ADC before enabling the digital transmit signals.

Phil so i'm left having to choose the best of a bad job based on everybodies comments, looks like i will have to go for direct wire and get it working close and see what the effects are at 2m afterwards and try and work with it, decisions decisions and not much clue Lol
The best way to do unknown projects is to prototype them. Start with the simplest, see how it goes, then extend once it's working or to make it work. There often isn't an 'off-the-shelf, will work for you' solution so it has to be found.

The more complicated the project, the more it has to do, the harder it will be to do it. Projects can become so involved they become an impossible task if having to do everything in one hit. The best approach is to trim the goal as much as possible, get the basics working, then build on that.

So, yes, start with short direct wire, then see how that fares when longer, is a good approach. It's easier to make decisions when one knows what does and doesn't work, than try and predict what will be needed. I agree that for commercial products things should ultimately be done properly, but a prototype can start improperly. Getting it to work is better than a perfect design which doesn't work.
 

Rampz

Well-known member
Look like using Hserin and Hserout talking to 3 picaxes might be an issue, with additional code needed to make it work, seems could be best to have 3x Serin and 3x Serout pins so each picaxe can send data when it wants over 3x RS232 links, the display slave can then keep checking the 3x Serin pins in a loop, is this a better solution?
 

lbenson

Senior Member
the display slave can then keep checking the 3x Serin pins in a loop, is this a better solution?
Only one background serial receive is available. SERIN is blocking, so if you issue a SERIN on one pin, until you time out or receive what you're looking for, anything sent on another pin will be lost. You may need to set up a call-and-response regime. For instance, your slaves could even be M2s with 2-byte serial background buffers (or 20X2s with 128 bytes). You send an address byte (HSEROUT pin can be disabled, then you can use any pin for SEROUT) that indicates: "anything for me?"; then responder sends NACK or whatever it has. After NACK or timeout or response is processed, you move to the next slave.
 

Rampz

Well-known member
Only one background serial receive is available. SERIN is blocking, so if you issue a SERIN on one pin, until you time out or receive what you're looking for, anything sent on another pin will be lost. You may need to set up a call-and-response regime. For instance, your slaves could even be M2s with 2-byte serial background buffers (or 20X2s with 128 bytes). You send an address byte (HSEROUT pin can be disabled, then you can use any pin for SEROUT) that indicates: "anything for me?"; then responder sends NACK or whatever it has. After NACK or timeout or response is processed, you move to the next slave.
So looks like I'm maybe better having my display picaxe being the master and the 3x other all being slaves, so the master can ask each slave in turn for data? And have that done in a loop basis?
Just looking for the best solution or setup, getting that right in my head before going further
 

PhilHornby

Senior Member
So looks like I'm maybe better having my display picaxe being the master and the 3x other all being slaves, so the master can ask each slave in turn for data? And have that done in a loop basis?
As per post #126 ;) :-
One way round this, is to alter the logic - with a single central Master, that polls the Slaves, one at a time.
As an alternative, you could use interrupts...

The 28X2/40X2 have three interrupts available (the 20X2 only has two).

The Interrupt Service Routine would issue a serin using a timeout and a qualifier.

This scheme only works with cooperative clients - it's not very useful as a general serial data solution. Fortunately, your clients would be extremely cooperative!

The clients need to prefix the data with some sacrificial character(s) and a qualifier. The very first character will always be lost, because it will sent before the serin is posted (I used Linefeed, because it came in handy for display on my debug device). There (probably) still needs to be a delay - to give the Master time to respond - before the qualifier and data is sent.

(Just to be clear - because it wasn't! - the interrupt is triggered by the falling edge of the Start Bit of the first character)

I use this scheme to good effect in the project mentioned in #105. (The ISR maintains a client 'database' in the scratchpad, which is read by the main loop. The background Serial Receive was already in use by the Webserver Picaxe comms.)
 
Last edited:

PhilHornby

Senior Member
Thinking about it ...

It might not actually need three separate handling routines, the 'mixing method' could be used, since each client can send data to identify itself.
 

hippy

Technical Support
Staff member
So looks like I'm maybe better having my display picaxe being the master and the 3x other all being slaves, so the master can ask each slave in turn for data?
That would seem the best way to do it with all slave outputs being diode mixed to a single serial input on the master display unit.

The master can ask a slave to send data, wait for that data to be received. No need for interrupts, and no real need to have any ID bytes indicating which slave is responding as the master knows who it asked to send data.
 

PhilHornby

Senior Member
The master can ask a slave to send data, wait for that data to be received. No need for interrupts...
There is, however, a potential issue, in that the 'slaves' are the ones doing time-sensitive work AIUI. They are going to have be 'interrupted', either literally or figuratively, if the Master polls them.

The Master is to all intents and purpose a data-logger/status display, if I understand the proposed architecture correctly.
 

Rampz

Well-known member
The Master is to all intents and purpose a data-logger/status display, if I understand the proposed architecture correctly.
As far as the slaves are concerned its data logging, further down the road so to speak, i want the master to stop the clock when a fault is received from any of the slaves and note the time, after which when the fault has cleared the master will restart the clock at the correct time again

Regards the slaves i think its most important time-sensitive job is not missing any activations from the tilt switch, if the stall condition is 300ms longer being actioned the time can be reduced, the low voltage cutoff the same 300ms won't matter

In a stall situation its likely the motor will have pulled its safety plug out therfore the clock WILL loose a function, maybe the clock or the chimes either way something will be out of sync so stop the clock till sorted

In a low voltage situation we will have been in mains failure for a week and its now time to stop the clock

If a request for data times out then likely the fuse has blown to the autodrive and lets stop the clock

Once a fault has been detected then not worried about receiving data after that, the display will have the job to stop the clock and record the time from the RTC likely to eeprom
 

PhilHornby

Senior Member
I want the master to stop the clock when a fault is received from any of the slaves and note the time, after which when the fault has cleared the master will restart the clock at the correct time again
I think it should toll one of the church bells 🔔 as well, to bring the villagers running :)

You could reverse the logic and use a message from the Slave as a kind of "watchdog" ... as in, if an "OK" message hasn't been received in a certain time period, then declare an 'emergency' (just in case the message doesn't get through - mice eating through the cables...that sort of thing!)
Regards the slaves i think its most important time-sensitive job is not missing any activations from the tilt switch, if the stall condition is 300ms longer being actioned the time can be reduced
There's a way of catching events, without actually using an interrupt for them - in the shape of the Interrupt-on-change FLAGS. This might simplify the logic used in the slaves. (@Hippy posted some demo code for using them - but I can't find it :( )
 
Last edited:

AllyCat

Senior Member
Hi,
There's a way of catching events, without actually using an interrupt for them - in the shape of the Interrupt-on-change FLAGS. This might simplify the logic used in the slaves. (Hippy posted some demo code for using them - but I can't find it :( )
Perhaps because it got attached (post #3) to another thread. ;)

Interestingly, the IOC flags (and interrupts in general) are available on ALL of the I/O pins of the 08M2, but on a more restricted range (perhaps only port B) on the other M2s (and apparently even fewer on the X2s). Also the "mapping" of the port pins on the 14M2 and 20M2 makes the SFR pin calculations a little tricky. :(

Cheers, Alan.
 

Rampz

Well-known member
You could reverse the logic and use a message from the Slave as a kind of "watchdog" ... as in, if an "OK" message hasn't been received in a certain time period, then declare an 'emergency' (just in case the message doesn't get through - mice eating through the cables...that sort of thing!)
Phil yes that was what i was thinking also by
If a request for data times out then likely the fuse has blown to the autodrive and lets stop the clock
Seems the more involved the project the more the care needed in selecting the picaxe to start with, not just a case of have i got enough pins, more the need of a deep knowledge of what each picaxe can do
Interestingly, the IOC flags (and interrupts in general) are available on ALL of the I/O pins of the 08M2, but on a more restricted range (perhaps only port B) on the other M2s (and apparently even fewer on the X2s). Also the "mapping" of the port pins on the 14M2 and 20M2 makes the SFR pin calculations a little tricky. :(
I didn't want to overload the project by saying everything i wanted from it, as Hippy says best to build a project with success's, but seems for this one would have been best to said all requirments at the start?

What we know

I'm going to have to communicate between picaxe's over RS232 for reliable communication

Still not sure which end is a Master or a Slave, is it the display sending requests or is it the autodrive sending data when its free to do so?

That would seem the best way to do it with all slave outputs being diode mixed to a single serial input on the master display unit.
So diode mixing all autodrives to the display, mixing being done after the RS232 convertor i assume, with the display have a RS232 convertor for each slave?

Then there is scratchpad, i moved to the 20X2 to make use of this, background data transfer, but then the issue of the master knowing who sent what and maybe missing data by being overwritten?
 
Last edited:

lbenson

Senior Member
but then the issue of the master knowing who sent what and maybe missing data by being overwritten
"Call and respond" should solve this. Presumably you're in a tight loop (no PAUSEs in the main loop--all timing done by other means)--you're likely to be able to query each slave several times a second (and perhaps usually receive a NACK if nothing has changed). If you need instantaneous response (e.g., to hitting an end stop), you can use interrupts.
 

Rampz

Well-known member
If you need instantaneous response (e.g., to hitting an end stop), you can use interrupts.
Ibenson, i tend to be using loops and counters for time function rather than pauses, the ability to query once a second would be plenty, the fault conditions i am trying to get from the slaves won't matter to a second, most of the responces will be nothing has changed, not sure if there is any advantage of reading the voltage at the slave, could be the only thing that would alter slightly

Everything at the moment is discussion towards the ideal hardware solution and then start coding step by step
 

PhilHornby

Senior Member
Interestingly, the IOC flags (and interrupts in general) are available on ALL of the I/O pins of the 08M2, but on a more restricted range (perhaps only port B) on the other M2s.
The Picaxe Manual documents SETINT restrictions (for the M2's) :-

08M2only inputs C.1 to C.4 may be used
14M2only inputs C.0, C.1 and C.2 may be used
18M2only inputs C.0, C.1, C.2 and C.4 to C.7 may be used
20M2only inputs C.1 to C.5 may be used

I've not investigated all variations (by any means), but I've successfully used the IOC flags with pin C.3 on a 14M2, when it wouldn't allow me to use an interrupt on the same pin. Since it was the only spare pin, this was quite fortuitous!

The 14M2 appears to allow access to 'Port A' - i.e. B.0?,B.1,B.2,C.3,C.4 & C.5? in Picaxe terms
The 20M2 extends it to 'Port C' as well - i.e. everything apart from C.0,B.5,B.6 & B.7 (if I've read the datasheets correctly!)
 

AllyCat

Senior Member
Hi,

The point (with PICaxe) is that the IOCs are (hardware) Interrupt FLAGS, but they do NOT generate an interrupt (i.e. they must be polled by the PICaxe program) ! The IOC Hardware is present on many (or even all) of the I/O pins of most recent PIC chips (and includes an Interrupt Enable register), but the PICaxe interpreter does not read any of them.

AFAIK, the PICaxe interpreter does not generate any "real" Interrupts at all with M2s (or even X2s ?), it only READS (polls) one internal "Status" register after executing each PICaxe Basic Instruction. In the M2s this (8-bit) register is (part of) only one of the Internal Ports, which in the case of the 14M2 and 20M2 are not the same (names) as the (PICaxe's) External port names. These chips have Three internal ports named A, B and C and I believe the PICaxe Interrupt reads only the Internal Port B. That's why only three (interrupt) pins are available on the 14M2 and five on the 20M2. The 08M2 has only one internal Port (actually named A in the base PIC) and the 18M2 has two, which do map one-to-one with the PICaxe's port pin numbers.

In principle, the PICaxe interrupts could be generated by ALL of the 08M2s I/O pins (and the 18M2's "port B") but the interpreter (firmware) specifically excludes certain pins which are primarily related to the Programming function, i.e. there is no physical (hardware) reason why the 08M2's C.0 and C.5 pins couldn't be used to generate an interrupt.

However, IMHO this thread is not the correct place to discuss such complexities - perhaps your other current discussion thread ?

Cheers, Alan.
 

PhilHornby

Senior Member
The point (with PICaxe) is that the IOCs are (hardware) Interrupt FLAGS, but they do NOT generate an interrupt (i.e. they must be polled by the PICaxe program)
I know, but in many cases, needing to know that something happened, is not the same as needing to respond to it immediately. (User presses switch, while program is waiting for a DS18B20 ... that sort of scenario).

I have seen recommendations (in this forum), that no work should be performed in the ISR - only the setting of a flag, for the main loop to check. The inbuilt IOC flags are very good match for that scenario.
 

AllyCat

Senior Member
Hi,
I have seen recommendations (in this forum), that no work should be performed in the ISR - only the setting of a flag, ...
IMHO that is a gross over-simplification (probably intended for novices) but it depends very much on your definition of "Work". Processing "data" can be fine (maybe even essential), so my "rule" (recommendation) would be that the ISR should (almost) NEVER use a PAUSE , and/or "Waiting" loops (e.g. DO : LOOP UNTIL <pin> ) except with great caution.

A particular example is in using the "HSERIN" Hardware with M2 chips (i.e. without the Background Receive function of X2s) where it may be absolutely essential to read the input buffer immediately. It's an application particularly dear to my heart and the main problem when writing the ISR is to determine when/whether it is "safe" to RETURN from the Routine. The issue is the horribly long (and undefined) time that it takes a PICaxe to execute a RETURN and then to execute another Interrupt, in time to receive another character (or strictly two) if a character arrives whilst the Return was being executed.

Also it must be appreciated that PICaxe "Interrupts" are a rather poor imitation of "Real" Interrupts. Even quite modest microcontrollers will normally have not only interrupts that can be executed "instantaneously", but their architecture may have "Interrupt Priority Registers" and/or "Vectored" interrupts (to different address labels) for the various different (types of) interrupt sources. So Yes, the IOC Flags are indeed a very useful feature, but they should not be confused with "real" Interrupts. ;)

Cheers, Alan.
 

AllyCat

Senior Member
Hi,

To return to the OP's recent questions. Personally, except for "simple" Hardware projects, I would normally recommend starting with a 20M2 (i.e. a 20 pin DIL socket). The basic pin-out is compatible with 14M2 and 08M2 chips, so the final project can be scaled down to the smaller packages (tested in the same socket) if they prove to be sufficient. Alternatively, if you really find that you need more "grunt", then the 20X2 will fit in the same socket (but I've never yet needed to). Or if you find that you want "more pins" (and understand the benefits of multiplexing I/O pins and/or the I2C Bus, etc.), then perhaps you should consider a multiple chip architecture, or another processor?

A "trick" I've considered for "smaller" projects has been to start with a 16-pin DIL socket, with power/ground connections at both ends (and maybe the regular "serial programming" pins adjacent to them). Perhaps even using the standard PICaxe 3.5 mm programming plug at one end and the "Legacy" 3-pin Programming Header pins at the other end. Then you can directly plug in either a 14M2 or two 08M2s end-to-end (for a faster/multi-tasking architecture).

IMHO, as far as processor-to-processor communications are concerned, in most cases the normal PICaxe SERIN/OUT commands should be adequate, because the Program-writer has control of "both ends" of the link (so delays/handshaking can be incorporated as required). These commands have the great advantage that they can access any (or even all) of the I/O pins. IMHO the HSERIN/OUT commands are mainly required when communicating with another computer (which might include the PICaxe Program Editor/Terminal). In these cases the baud rate and/or character repetition rate may be outside the control of the Program-writer. But HSERIN/OUT has the disadvantage that only a few pins can be used (conveniently) and also the M2's HSERIN Hardware does not support the "N" (Idle-Low) protocol used by the PICaxe Editor/Terminal. :(

Cheers, Alan.
 

hippy

Technical Support
Staff member
But HSERIN/OUT has the disadvantage that only a few pins can be used (conveniently) and also the M2's HSERIN Hardware does not support the "N" (Idle-Low) protocol used by the PICaxe Editor/Terminal.
That is indeed unfortunate but it's part of the silicon design which we have no control over. I have never understood why Microchip would support inversion on output but not on input.. I don't think anyone else has figured out their reasoning either.

Other disadvantages are that the pins used are somewhat 'all over the place'.. Again, something beyond our control. There are some options to move the pins elsewhere under POKESFR control of 'alternative pin function' but that's not otherwise supported by Basic commands. And I can't say off-hand how well it works or which chips support it.

HSEROUT on the 08M2 and 14M2 use the same pin as SERTXD, but at least HSERIN and HSEROUT placement allows swapping between 08M2 and 14M2, 20M2 and 20X2.

I believe these would be the full details -
Code:
HSERSETUP Bbaud_mhz, %rtb
                      |||
                      ||`--- Background receive
                      |`---- Tx polarity : 0=T, 1=N
                      `------Rx polarity : 0=T, 1=N

                      T = Traditional UART idle high
                      N = Normal RS232     idle low
Code:
       .-------------.--------------.--------.------.
       | HSERIN  T/N | HSEROUT  T/N | Rx Buf | %rtb |
.------|-------------|--------------|--------|------|
| 08M2 | C.1     T   | C.0 SO   T/N |     2  | %0t0 | -.
| 14M2 | B.1     T   | B.0 SO   T/N |     2  | %0t0 | -'
| 18M2 | B.2     T   | B.5      T/N |     2  | %0t0 |  
| 20M2 | B.6     T   | C.0      T/N |     2  | %0t0 | -.
|------|-------------|--------------|--------|------|  |
| 20X2 | B.6     T/N | C.0      T/N |   128  | %rtb | -'
| 28X2 | C.7     T/N | C.6      T/N |  1024  | %rtb |
| 40X2 | C.7     T/N | C.6      T/N |  1024  | %rtb |
`------^-------------^--------------^--------^------'  |
                                                       |
         These have HSERIN/HSEROUT pins in the same |--'
          position relative to the top of the chip  |
The real benefit of HSERIN is to not have to worry about being ready to receive data when it is sent. The advantage of HSEROUT is when one wants an exact or unusual baud rate, the fastest data transmission rates. Otherwise SERIN and SEROUT are usually fine.
 

Goeytex

Senior Member
The alternate pin function works fine. Rev-Ed actually relocates the hserout/hserin pins from the factory default locations. To move them back to the factory locations ( Picaxe Pins C.2 ,C.1)

Example for 14M2/20M2:

Pokesfr %01011101,%00000000
 

AllyCat

Senior Member
Hi,
I have never understood why Microchip would support inversion on output but not on input.. I don't think anyone else has figured out their reasoning either.
As an ex-IC designer, I suspect that it was just a "mistake". Either they "forgot" to include the XOR gate, or more likely the design that they implemented didn't work correctly (so they "corrected" the data sheet, rather than the Hardware). ;)

Yes indeed, the APFCON register can be very useful; the HSERIN on the 08M2 uses the same pin as the I2C Bus SCL line. But it can be swapped onto the normal SERIN (Programming) pin, which would be absolutely ideal, if it wasn't Idle-High only. :( However, it can be "fixed" with just a single external transistor (bipolar or FET) on the 08M2, or by using the internal DSM or a comparator (and a few "spare" pins) on the larger M2s.

Personally, when initially planning a hardware design, I find the "Pin Allocation Table", quite near to the start of the relevant base PIC Data Sheet ("Advanced Technical Details" link) to be particularly useful in finding where the dedicated functions are located (e.g. all the Hardware Module functions, IOC, Weak Pullups, etc., etc.).

Cheers, Alan.
 

hippy

Technical Support
Staff member
The alternate pin function works fine.
I was thinking in terms of caveats, that the firmware may switch things back to its desired defaults. I am sure I ran into that with some interface but cannot recall which. Trying to turn 18X inputs to outputs failed because of that, though the outputs could be made inputs.

It may be possible to make things work for some or all cases, but it may mean relinquishing Basic commands and having to use POKESFR and PEEKSFR to achieve what is desired. That may not be an insurmountable problem but isn't for the faint-hearted or those who don't have a good understanding of the underlying silicon, good PICAXE programming skills.
 

Rampz

Well-known member
Going back to basics with the communication over 2-3m distance, the best way so far being the RS232 route, but am i over complicating the issue, thinking out of the box as i often do, i would think i can have 2-3m of cable with a LED at the end and it will work happily etc so going further why not use an optocoupler either end, it would be the same as switching a led on a 2-3m cable wouldn't it?
I don't expect to get false switching from anything induced along the cable since it has a led load on it, Thoughts please?
 
Top