Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 11:20 05 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Odd serial data for micromite

     Page 1 of 3    
Author Message
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 08:32pm 16 May 2017
Copy link to clipboard 
Print this post

Could anyone think of a way that I might be able to send and receive 1200,7,e,1,N from a Micromite ? Could I receive at 1200,8 read in the data and drop the 8th bit?
Graeme
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 09:05pm 16 May 2017
Copy link to clipboard 
Print this post

If i read it right, a 1200 baud rate with 7 databits,1 even parity bit and one stop bit has in total 9 bits.
If you setup 1200 baud , 8 bits, no parity and one stop bit would also be 9 bits.
Receiving is easy as what you already thought. Just drop the 8th bit.
Easiest to do an AND with 127 (&B01111111)

Sending would require you to take the 7 bit data and use the 8th bit as a parity.
For even parity you would need to count the 1's and if the count is uneven then set the parity bit. The count AND 1 will give you a 0 or 1 for even or uneven.

Edited by MicroBlocks 2017-05-18
Microblocks. Build with logic.
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 10:14pm 21 Jun 2017
Copy link to clipboard 
Print this post

Not having much luck here so I thought I would post my try and see if someone could see the error in my method. Just dealing with the transmit side first, as per the limited documentation I have, the query to acknowledge active for the device attached to the micromite is "a!" at 1200,7,e,1 which I have worked this way:

"a"= ASC 97 =1100001 and adding parity bit= 11000010 which= chr$(194) at 8 bits no parity
"I"= ASC 73 =1001001 and adding parity bit= 10010010 which= chr$(146) at 8 bits no parity
So I am sending the query string as chr$(194)+chr$(146)

QUERY$=Chr$(194)+Chr$(66) 'ACKNOWLEDGE ACTIVE a!

Pin(7)=1
Open "COM2:1200" As #1
Print Time$; " THE QUERY STRING IS ";QUERY$
Print #1, QUERY$
Pause 100
Pin(7)=0
REPLY$=Input$(10,#1)
Close #1

Print Time$;" THE REPLY STRING IS ";REPLY$


Looping the Com2 pins I can see my data back but I cant get a response from the device.
Graeme
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8592
Posted: 11:04pm 21 Jun 2017
Copy link to clipboard 
Print this post

I think you have put the parity bit at the wrong end - it should be the MSB
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3663
Posted: 11:17pm 21 Jun 2017
Copy link to clipboard 
Print this post

Also, you probably want a semi-colon (;) at the end of each PRINT #1

(unless you want CR / LF sent as well as your chars)

John
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 12:00am 22 Jun 2017
Copy link to clipboard 
Print this post

"a" = CHR$(97) = 0110 0001 has three ones, use OR 128 (1000 0000) = 1110 0001 (225)
"!" = CHR$(73) = 0100 1001 has three ones, use OR 128 (1000 0000) = 1100 1001 (201)

Query$ = CHR$(225) + CHR$(201)

Not able to test it, but i think those values are right.

Microblocks. Build with logic.
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 12:13am 22 Jun 2017
Copy link to clipboard 
Print this post

  Quote  I think you have put the parity bit at the wrong end - it should be the MSB

Does this mean that a character such as "!" which is ascii 33 &B100001 having even number of ones would still be the same value as the msb will be a zero?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8592
Posted: 12:27am 22 Jun 2017
Copy link to clipboard 
Print this post

  Quote  Does this mean that a character such as "!" which is ascii 33 &B100001 having even number of ones would still be the same value as the msb will be a zero?


Yes
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 12:38pm 22 Jun 2017
Copy link to clipboard 
Print this post

Thank you for your direction and assistance. Still no response from the device. I might drag out one of my old pc's with a serial port and see if I can pump some life back into it. Will see if I get any response at 1200,7,e with it.
Graeme
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5913
Posted: 01:23pm 22 Jun 2017
Copy link to clipboard 
Print this post

Try this
  Quote  
a$=
"hello there!"

FOR n = 1 TO LEN(a$)
ch$=
MID$(a$,n,1)
che$=even$(ch$)

PRINT ch$," ",BIN$(ASC(che$),8)," ",ASC(che$)

NEXT n

FUNCTION even$(c$)
' given a character, returns a character with even parity set in 8th bit
LOCAL n, par, a
a =
ASC(c$)
FOR n = 1 TO 7
a = a*
2
par = (a
AND &B10000000) XOR par
NEXT n
even$ =
CHR$((ASC(c$) AND &B01111111) OR par)
END FUNCTION


It's not the most efficient way of adding parity but hopefully it is clear enough to follow.

Receiving characters is the easy part. Simply mask off the 8th bit.
ch$= chr$(asc(ch$) AND &B01111111))

Jim
VK7JH
MMedit   MMBasic Help
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5913
Posted: 02:48pm 22 Jun 2017
Copy link to clipboard 
Print this post

You will also need to include the cr lf pair in the parity code.
  Quote   a$="hello there!"+CHR$(13)+CHR$(10)


cr with even parity is chr$(141)
lf stays the same.

Jim
VK7JH
MMedit   MMBasic Help
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 06:05pm 22 Jun 2017
Copy link to clipboard 
Print this post

Thanks Jim for your code but I think I have a more serious issue with the serial transfer. I am not sure if the response is inverted or modified in some way. I have connected the device to a serial port @1200,7,E,1 with Putty but still don't read a response. I have measured the current draw of the device and it sits at 5mA until I address it, then it raises to 9mA for a short duration. It is either recognising the command and waking from sleep but giving some weird response or it is not recognising the command at all. Not sure what to try from now.
Graeme
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 06:50pm 22 Jun 2017
Copy link to clipboard 
Print this post

Found a bit more information that describes the timing required. It seems the device requires a BREAK of at least 12mS then a MARK at least 8.33mS before the command.
Tried to upload the diagram but it went to black, sorry. Not sure how to achieve this and still maintain the serial port.
Graeme
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2290
Posted: 07:05pm 22 Jun 2017
Copy link to clipboard 
Print this post

one kludge would be to add a 1k resistor in series with the serial port TxD line. then connect a spare pin of the micromite to the end of the resistor that is away from the micromite.

- when this pin is set as input (default) serial transmission can occur as normal,
- when set to '0' and output, the TxD line will be forced low,
- when set to '1' and output, the TxD line will be forced high,
- when set back to input, serial transmission can resume.

the 1k resistor allows the pin to 'override' the TxD output. the 3mA required to force a different state to the one TxD is in is well within the drive ability of the micromites I/O pins.


cheers,
rob :-)
Edited by robert.rozee 2017-06-24
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5913
Posted: 07:11pm 22 Jun 2017
Copy link to clipboard 
Print this post

This might be a use for peterm's bitbanger csub.

Jim
VK7JH
MMedit   MMBasic Help
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 09:18pm 22 Jun 2017
Copy link to clipboard 
Print this post

@Rob
Tried as suggested:
QUERY$(1)=Chr$(255)+Chr$(33) 'ADDRESS QUERY ?!
QUERY$(2)=Chr$(225)+Chr$(33) 'ACKNOWLEDGE ACTIVE a!
QUERY$(3)=Chr$(225)+Chr$(201)+Chr$(33) 'SEND IDENTIFICATION aI!
Open "COM2:1200" As #1
For I=1 To 3
Print Time$; " THE QUERY STRING IS ";QUERY$(I);" ";
Pin(7)=1
Pin(24)=0 'SET THE BREAK >20mS VIA 1K RESISTOR
Pause 20
Pin(24)=1 'SET THE MARK >8.3mS VIA 1K RESISTOR
Pause 10
Pin(24)=0
Print #1, QUERY$(I);
Pause 200
Pin(7)=0
REPLY$=Input$(10,#1)

Print Time$;" THE REPLY STRING IS ";REPLY$
Next I
Close #1


Hope I got the BREAK and MARK the right way round. Had a play round with extending the timings but still no go.

Graeme
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 09:28pm 22 Jun 2017
Copy link to clipboard 
Print this post

@Jim
Currently I have the need to interface these devices into the existing 170 chips and I think that Peter's BitBanger Csub is for the 470 chips. Great thought though.
Graeme
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5913
Posted: 09:41pm 22 Jun 2017
Copy link to clipboard 
Print this post

  OA47 said   @Jim
Currently I have the need to interface these devices into the existing 170 chips and I think that Peter's BitBanger Csub is for the 470 chips. Great thought though.
Graeme

I am using a version of it on the 170 to control some Arlec switches.

VK7JH
MMedit   MMBasic Help
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 09:45pm 22 Jun 2017
Copy link to clipboard 
Print this post

I managed to find another copy of the timing diagram:



 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 09:47pm 22 Jun 2017
Copy link to clipboard 
Print this post

  Quote  I am using a version of it on the 170 to control some Arlec switches.

Jim is that the one that is labelled for the MM+?
 
     Page 1 of 3    
Print this page
© JAQ Software 2024