18M2 Question

AlbertZ

Senior Member
I want to use the PICAXE-18 High Power Project board to demonstrate control of motors using a keypad. My plan is to transmit the characters from the keyboard using a peripheral processor (08M2). My question is can I use pins C.3 and C.4 as my serial Rcv and TxD pins, or are they reserved strictly for downloading programs?
 

westaust55

Moderator
If your keypad is a simple 4x4 version and you have a spare ADC input you can use the 18M2 to directly "read" the keypad.
 

AlbertZ

Senior Member
If your keypad is a simple 4x4 version and you have a spare ADC input you can use the 18M2 to directly "read" the keypad.
Yes, that is quite true and I had considered that but decided to go the peripheral route instead. First it allows me to use an 08M2 as the keypad’s peripheral processor because all I need is a single ADC pin. But more importantly, it frees the master processor from needing to repetitively take ADC readings to make sure it doesn’t miss a single keypress whenever it should happen to occur. My thought was to build the ADC resistor network on a 08M2 proto-board then I could easily use the "smart" keypad for other experiments. Incidentally, I'll be using a 4x3 matrix keypad and decoding the values using a series of case statements. Here is the schematic:
matrix keypad circuit.jpg
 

BESQUEUT

Senior Member
But more importantly, it frees the master processor from needing to repetitively take ADC readings to make sure it doesn’t miss a single keypress whenever it should happen to occur. [/ATTACH]
OK...
but now the master processor needs to repetitively read serial port to make sure it doesn’t miss a byte...
 

AlbertZ

Senior Member
Not entirely sure of your question but please check DISCONNECT command in manual 2...
Here is what I expect to happen when a keypad button is pressed: As soon as an input character has been decoded, the peripheral processor (08M2) will raise its output line to a high level to alert the master processor that there is valid data available and then “listen” on its input line for the instruction to send the data. The master processor will send a brief HIGH pulse on its output pin that is connected to the 08M2’s input when it’s ready to receive the data. I want to use the pulsin command to receive the master processor’s “Data Terminal Read” command. As soon as the peripheral processor has received the DTR command, it lowers its output pin and sends the character (serially) to the master processor, which is already waiting to receive it.

Here is the code snippet for the peripheral processor:
Code:
do 	
wait_for_keypress:
  readadc fromKP, junk
	if junk < 5 then wait_for_keypress

	pause 60				' debounce keypress	
	readadc10 fromKP, key		' get ADC value
		
wait_for_release:	
	readadc fromKP, junk
	if junk > 5 then wait_for_release
	
	select case key				' decode keypress
		case < 384 : char = 49		' 1
		case < 401 : char = 50		' 2
		case < 435 : char = 51		' 3
		case < 474 : char = 52		' 4
		case < 499 : char = 53		' 5
		case < 558 : char = 54		' 6
		case < 628 : char = 55		' 7
		case < 696 : char = 56		' 8
		case < 767 : char = 57		' 9
		case < 884 : char = 42		' *
		case < 976 : char = 48		' 0
		else	     : char = 35		' #
	end select
	
	high toMP					' data available
	pulsin fromMP,1, junk			' junk is junk,
	low toMP					' we're just waiting
	pause 2					' allow time for MP
							' to set up serin
	serout toMP,N2400_8,(char)		' send char to MP	
loop
and the code snippet for the master:
Code:
' === Main Program Loop ===	
wait_for_keypress:
do
  	pause 100					' pretend to be busy
	if KPflag = 1 then gosub getChar	' go get new char
loop

' ============== End Main Program - Subroutines Follow ==============
getChar:
	pulsout C.3, 2			'10uS "send it" pulse					
	pause 1				' allow time for keypad to 
						' lower its output
	serin C.4, N2400_8, char	' get char
	sertxd (char, cr, lf)		' send it to terminal
	return
 

BESQUEUT

Senior Member
Here is what I expect to happen when a keypad button is pressed: As soon as an input character has been decoded, the peripheral processor (08M2) will raise its output line to a high level to alert the master processor that there is valid data available and then &#8220;listen&#8221; on its input line for the instruction to send the data. The master processor will send a brief HIGH pulse on its output pin that is connected to the 08M2&#8217;s input when it&#8217;s ready to receive the data. I want to use the pulsin command to receive the master processor&#8217;s &#8220;Data Terminal Read&#8221; command. As soon as the peripheral processor has received the DTR command, it lowers its output pin and sends the character (serially) to the master processor, which is already waiting to receive it.
Hard handcheck... This will do the job.
 

AlbertZ

Senior Member
Not entirely sure of your question but please check DISCONNECT command in manual 2...
I have reviewed the disconnect command information as supplied by the manual. As I understand it, this command disconnects the PICAXE so that it does not scan for new downloads. Now what I want to do is to use the download pin for serial communication with another chip and so it is necessary to disable the scanning.

With respect to the use of the disconnect command, it seems all I need to do is insert it somewhere at the start of the master program. The downside would be that I would have to do a hard-reset whenever I wanted to download a new program. Do I understand this correctly or am I still missing something?

However, after reading the explanation of the disconnect command it seems to imply that I need to use the serrxd command instead of the serin command for reading the data coming from the peripheral processor.

Is the use of serrxd a requirement when using the download pin as a serial input?

If so, why won't serin do the same job?
 

BESQUEUT

Senior Member
I have reviewed the disconnect command information as supplied by the manual. As I understand it, this command disconnects the PICAXE so that it does not scan for new downloads. Now what I want to do is to use the download pin for serial communication with another chip and so it is necessary to disable the scanning.

With respect to the use of the disconnect command, it seems all I need to do is insert it somewhere at the start of the master program. The downside would be that I would have to do a hard-reset whenever I wanted to download a new program. Do I understand this correctly or am I still missing something?

However, after reading the explanation of the disconnect command it seems to imply that I need to use the serrxd command instead of the serin command for reading the data coming from the peripheral processor.

Is the use of serrxd a requirement when using the download pin as a serial input ?
IMHO you are right. When I do that (using sertxd) I also install a jumper to be detected before sending the disconnect command. So I can reprogram the Picaxe with no need to do a hard reset.
If so, why won't serin do the same job?
Maybe simply because there are no pin name for serial in and serial out pins...
 

westaust55

Moderator
You could put some code before the DISCONNECT command that would give you a chance to download a new program after power up without having to instigate a full hard rest procedure. This would delay the starting of the primary program at power up.
Code:
For b0 = 1 To 1000
Pause 5
Next
As the SerialIn pin is checked (at least) at the end of each command that gives ample opportunity to start a download in the first 5 seconds.

The SerialIn pin for an 18M2 is pinC.4
Refer: http://www.picaxe.com/Site_Resources/Media/Site_1/pinout/pinout18m2.jpg
 

AlbertZ

Senior Member
Thanks everyone, that answers my original question regarding the serial in pin. Thanks for the work-arounds as well.
 

hippy

Ex-Staff (retired)
Is the use of serrxd a requirement when using the download pin as a serial input?

If so, why won't serin do the same job?
On some PICAXE the download serial in can be read using either SERIN or SERRXD. On others only the SERRXD command can be used.

If the pinout diagrams show an "X.Y" pin designation for the download serial in pin then the pin can be used with SERIN and other input commands ( COUNT, PULSIN etc ). If it doesn't it is only usable with SERRXD.
 

AlbertZ

Senior Member
On some PICAXE the download serial in can be read using either SERIN or SERRXD. On others only the SERRXD command can be used.

If the pinout diagrams show an "X.Y" pin designation for the download serial in pin then the pin can be used with SERIN and other input commands ( COUNT, PULSIN etc ). If it doesn't it is only usable with SERRXD.
I have looked at every pinout diagram in the manual and nowhere do I see an "X.Y" pin designation. Where would I look to find this designation?
 

hippy

Ex-Staff (retired)
"PICAXE Manual 1 - Getting Started" ( pages 9 through 11 ), and also through clicking on "Input/Output Table" in the Workplace Explorer panel of PE6. For example -

For the 08M2 this shows "(In) Serial In / C.5" on leg 2, so one can use SERIN C.5.

Same for 14M2 (C.5) and similar for 18M2 (C.4).

For the 20M2 it shows only "Serial In" on leg 2 so SERIN cannot be used, only SERRXD.

X1 and X2 are also "Serial In", SERRXD only.

Also in the default chip graphic in the Simulation panel of PE6, the graphic will show a pin number against those which can be used with SERIN and "RXD" where only SERRXD can be used.
 

westaust55

Moderator
I have looked at every pinout diagram in the manual and nowhere do I see an "X.Y" pin designation. Where would I look to find this designation?
Further to hippy's reply, the pin out diagrams are also available on the PICAXE website here:
http://www.picaxe.com/What-is-PICAXE/PICAXE-Pinouts/

At post 10 I (went 1 step further and) gave you a link specifically to the 18M2 chip pin out diagram since that as the subject of the thread title.
 

AlbertZ

Senior Member
Thanks to all who responded. I looked at all those links, but what I couldn't get through my thick head was the meaning of "X.Y" designation.
 
Top