Name:
serin
Syntax:

SERIN pin,baudmode,(qualifier,qualifier...)

SERIN pin,baudmode,(qualifier,qualifier...),{#}variable,{#}variable...

SERIN pin,baudmode,{#}variable,{#}variable...

Additional optional timeout syntax options for M2, X1 and X2 parts:

SERIN [timeout], pin,baudmode,(qualifier...)

SERIN [timeout], pin,baudmode,(qualifier...),{#}variable,{#}variable

SERIN [timeout], pin,baudmode,{#}variable,{#}variable

SERIN [timeout,address], pin,baudmode,(qualifier...)

SERIN [timeout,address], pin,baudmode,(qualifier...),{#}variable,{#}variable

SERIN [timeout,address], pin,baudmode,{#}variable,{#}variable

Pin - is a variable/constant which specifies the i/o pin to use.

Baudmode - is a variable/constant (0-7) which specifies the mode:

Txxx give a true output (idle high).

Nxxx give an inverted output (idle low) .

 

For older 08 / 08M / 18 / 18A / 28 / 28A parts

4MHz 8MHz 16MHz
T300_4 T600_8 T1200_16
T600_4 T1200_8 T2400_16
T1200_4 T2400_8 T4800_16
T2400_4 T4800_8 T9600_16
N300_4 N600_8 N1200_16
N600_4 N1200_8 N2400_16
N1200_4 N2400_8 N4800_16
N2400_4 N4800_8 N9600_16

For all other parts (e.g. all X1, X2, M2 parts)

4MHz 8MHz 16MHz 32MHz 64MHz
T600_4 T1200_4 T2400_16 T4800_32 T9600_64
T1200_4 T2400_8 T4800_16 T9600_32 T19200_64
T2400_4 T4800_8 T9600_16 T19200_32 T38400_64
T4800_4 T9600_8 T19200_16 T38400_32 T76800_64
N600_4 N1200_8 N2400_16 N4800_32 N9600_64
N1200_4 N2400_8 N4800_16 N9600_32 N19200_64
N2400_4 N4800_8 N9600_16 N19200_32 N38400_64
N4800_4 N9600_8 N19200_16 N38400_32 N76800_64

Qualifiers - are optional variables/constants (0-255) which must be received in exact order before subsequent bytes can be received and stored in variables.

Variable(s) - receive the result(s) (0-255). Optional #'s are for inputting ASCII decimal numbers into variables, rather than raw characters.

Timeout - is an optional variables/constants which sets the timeout period in milliseconds.

Address - is a label which specifies where to go if a timeout occurs.

Description:

Serial input with optional qualifiers (8 data, no parity, 1 stop).

The serin command is used to receive serial data into an input pin of the microcontroller. It cannot be used with the serial download input pin, which requires use of the serrxd command instead.

Pin specifies the input pin to be used. Baud mode specifies the baud rate and polarity of the signal. When receiving RS232 level data using a simple resistor interface, use N (inverted) signals. When using a MAX232 type interface use T (true) signals. The protocol is fixed at N,8,1 (no parity, 8 data bits, 1 stop bit).

Note that the 4800 baud rate is available on the M, X, X1 and X2 parts. Note that the microcontroller may not be able to keep up with processing complicated datagrams at higher speeds - in this case it is recommended that the transmitting device leaves a short delay (e.g. 2ms) between each byte.

Qualifiers are used to specify a 'marker' byte or sequence. The command serin 1,N2400,("ABC"),b1 requires to receive the string "ABC" before the next byte read is put into byte b1.

Without qualifiers serin 1,N2400,b1 the first byte received will be put into b1 regardless.

All processing stops until the new serial data byte is received. This command cannot be interrupted by the setint command. The following example simply waits until the ascii sequence "go" is received: serin 1,N2400,("go")


IMPORTANT! It is a very common mistake to accidentally use a qualifier by mistake like this:

serin 1,N2400,(b1).

If you do not want a qualifier do not use brackets!

serin 1,N2400, b1

 

The M2, X1 and X2 parts can take an optional timeout value and address at the start of the command. The timeout value, set in milliseconds, is the length of time the serin command will wait for a serial command to be detected. After the timeout period , if no signal is detected, program flow will jump to the time out address. After using this command you may have to perform a hard reset to download a new program to the microcontroller.

A maximum of 4800 baud is recommended for complicated serial transactions at 8MHz. Internal resonators are not as accurate as external resonators, so in high accuracy applications an external resonator device is recommended. However microcontrollers with an internal resonator may be used successfully in most applications, and may also be calibrated using the calibfreq command if required.

 

Reading number values

When the #variable format is used received data will be taken and converted to a number.

All characters received are ignored until the first ASCII digit character is received. A number is then determined until a ASCII non-digit character is received. The value stored in the variable will be number represented by the digit characters received. Note that the #variable will not complete until the number has been terminated by a non-digit character being received.

 

All 8 and 14 pin chips

Due to the internal structure of input3 (C.3) on these chips, a 1N4148 diode is required between the pin and V+ for serin to work on this particular pin ('bar' end of diode to V+) with this circuit. All other pins have an internal diode.

All 20 pin chips

Due to the internal structure of input6 (C.6) on this chip, a 1N4148 diode is required between the pin and V+ for serin to work on this particular pin ('bar' end of diode to V+) with this circuit. All other pins have an internal diode.

Applies To:
All
See Also:
Related Create:
Share:
Print:

Receive serial data

Receive serial data, and write it to EEPROM locations 0 to 63

Code Example:
main:	for b0 = 0 to 63	; start a loop
	  serin 6,N2400,b1	; receive serial value
	  write b0,b1		; write value into b1
	next b0			; next loop
Copy Code Submit an Example

Submit Your Own Code!

You must be logged in to submit code examples. Login now.

Comments

  • Login to leave a comment.