Microsquirt Serial Protocol Question

This forum is for the discussion of other projects on Megasquirt/Microsquirt hardware that don't fit into any of the other forums

Moderators: jsmcortina, muythaibxr

Post Reply
alk415
MS/Extra Newbie
Posts: 6
Joined: Tue Jun 21, 2016 7:45 am

Microsquirt Serial Protocol Question

Post by alk415 »

Hello,

I'm developing a control module for a dyno that passes serial information between a computer running Tunerstudio and a Microsquirt. The Microsquirt is loaded with the latest stable firmware release. The reason I'm doing this is because the controller needs to use several of the data parameters.

I'll start of by saying that I'm referencing the protocol described here: http://www.msextra.com/doc/pdf/Megasqui ... -10-28.pdf. My hardware works great and I can get Tunerstudio and Microsquirt to communicate if I simply pass the incoming bytes along. However, to extract the data, I'd like to read packets. I'm running into a slight issue however: Tunerstudio only sends the legacy commands to the Microsquirt. This is incredibly annoying as the wrapper containing the size bytes, which aren't included in the legacy commands, are key. Without them, I cannot employ the DMA module in my MCU to transfer large packets without loading down the CPU. Is there an option in Tunerstudio that I've missed that prevents it from sending out legacy commands? Any insight is highly appreciated.
racingmini_mtl
Super MS/Extra'er
Posts: 9128
Joined: Sun May 02, 2004 6:51 am
Location: Quebec, Canada
Contact:

Re: Microsquirt Serial Protocol Question

Post by racingmini_mtl »

Normally, TS would send an 'F' command in the legacy format (so just 'F') and when it receives the response that the protocol to use is the new one, it switches to the new serial protocol. If your device doesn't transfer either the query or the response, TS uses the legacy protocol. There are a few other legacy commands sent also to establish that there is a device connected to the serial port before sending the 'F' command.

Jean
jbperf.com Main site . . . . . . . . . . . . . . . . . . . . . . jbperf.com Forum
Image
piledriver
Super MS/Extra'er
Posts: 1679
Joined: Tue Oct 27, 2009 6:24 am
Location: Van Alstyne, Texas

Re: Microsquirt Serial Protocol Question

Post by piledriver »

Is there any way you could just perhaps simply parse a running datalog (opened r/o) like Megalogviewer can?
(perhaps too much delay, but might be consistent)

Do it on a ramdisk and the I/O overhead would be minimal.
Always doing things the hard way, MS2 sequential w/ v1.01 mainboard, LS2 coils. 80 mile/day commuter status.
alk415
MS/Extra Newbie
Posts: 6
Joined: Tue Jun 21, 2016 7:45 am

Re: Microsquirt Serial Protocol Question

Post by alk415 »

So I've written an initialization sequence that looks for the 'F' command, and sure enough it came from TunerStudio. The microsquirt responded with 002, which is supposedly the current serial version.

However, after passing the query response to TunerStudio, the next packet that comes out of Tunerstudio is an 'r' command with a prefix of 0x00 and 0x07. According to the protocol documentation, however, the size of this command should be 12 bytes, not 7? Is the documentation outdated? A value of 7 would make sense if the size value did not include the two size bytes and the four CRC32 bytes. The documentation claims that those 6 bytes are included though...

Perhaps I am framing my packets incorrectly? I'm having the controller wait for the line to go idle (11 baud cycles of inactivity) and then declaring the first incoming byte after that as the start of a new packet. I assume that Tunerstudio sends packets out synchronously, but I could be wrong.
racingmini_mtl
Super MS/Extra'er
Posts: 9128
Joined: Sun May 02, 2004 6:51 am
Location: Quebec, Canada
Contact:

Re: Microsquirt Serial Protocol Question

Post by racingmini_mtl »

alk415 wrote:The documentation claims that those 6 bytes are included though...
That part is wrong: the size does not include the size and CRC-32 fields.
alk415 wrote:Perhaps I am framing my packets incorrectly? I'm having the controller wait for the line to go idle (11 baud cycles of inactivity) and then declaring the first incoming byte after that as the start of a new packet. I assume that Tunerstudio sends packets out synchronously, but I could be wrong.
The packets are sent synchronously but you may need to wait longer just in case there is something interrupting the transmission at just the wrong time which causes a few missed cycles. The serial code on the MS side is a lot looser than that before it declares a broken command.

Jean
jbperf.com Main site . . . . . . . . . . . . . . . . . . . . . . jbperf.com Forum
Image
alk415
MS/Extra Newbie
Posts: 6
Joined: Tue Jun 21, 2016 7:45 am

Re: Microsquirt Serial Protocol Question

Post by alk415 »

Hrm that seems like a pretty serious mistake in the documentation. Does anyone maintain the msExtra website? Are there any other major mistakes I should be aware of?

In any case, the microsquirt now only returns an error packet (0x80) indicating that there was an underrun timeout. I've scoped all of the signals and verified that each byte is sent within less than a few microseconds after the preceding byte, so the 25ms timeout trigger should not be the cause. Tunerstudio isn't sending a new packet (after it receives the MicroSquirt response) within 25ms though. I don't think that should be a problem though... Reading the actual firmware's c files indicates that the 0x80 error response is actually the response for any undefined behavior as well, so I guess the problem isn't necessarily a timeout one. Could it be that I'm sending my bytes too quickly after one another? I tried adding a few milliseconds of delay between packet transmission to no avail....

Anyway, thanks for your insight so far Jean! It has been very useful!
alk415
MS/Extra Newbie
Posts: 6
Joined: Tue Jun 21, 2016 7:45 am

Re: Microsquirt Serial Protocol Question

Post by alk415 »

So here's an update: my setup works very efficiently with the DMA and I can parse all of the packets between TunerStudio and the Microsquirt.

I'm now a little confused as to which packet actually contains the data I want (rpm, tps, afr1, etc.). I noticed that Tunerstudio never sends the 'A' command to the Microsquirt, but it is constantly reading data using the 'r' command. According to the ini file for the firmware that I'm using (3.4.2), the Microsquirt's page 6, which doesn't correspond to any of the Tunerstudio pages, contains the outpc data. As I understand the outpc data is the response to an 'A' command and it contains all of the realtime data that I need. However, Tunerstudio never requests page 6 when it issues an 'r' command. But Tunerstudio on my laptop is synced and displaying the realtime data, so clearly it's coming in somehow.

Does anyone know which table/page actually contains the outpc information? I noticed that Tunerstudio does access table 7 with the 'r' command. But when I try to get information from there, using the offsets described in the outpc area of the ini file, I get incorrect data. Perhaps I'm waiting for the wrong offset (0) in table 7?
Alfagta
Experienced MS/Extra'er
Posts: 239
Joined: Wed Aug 21, 2013 2:54 am

Re: Microsquirt Serial Protocol Question

Post by Alfagta »

Normally outpc is table 7.

BR
Alfa 156 GTA
Alfa 75 Race Car MS III -- alway latest FW
Alfa 164 V6 Turbo
Alfa 155 2,5TD RIP
Test MS II --always latest FW
Tunerstudio V2.6.11 Registered
MegaLog Viewer V3.4.04 Registered
jsmcortina
Site Admin
Posts: 39585
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK
Contact:

Re: Microsquirt Serial Protocol Question

Post by jsmcortina »

alk415 wrote:I'm now a little confused as to which packet actually contains the data I want (rpm, tps, afr1, etc.). I noticed that Tunerstudio never sends the 'A' command to the Microsquirt, but it is constantly reading data using the 'r' command. According to the ini file for the firmware that I'm using (3.4.2), the Microsquirt's page 6, which doesn't correspond to any of the Tunerstudio pages, contains the outpc data.
Why do you think it is table 6? (It isn't.)

If you don't understand the comms, I would strongly suggest that you enable the "comms log debug" in TunerStudio and study the TunerStudioAppDebug.txt that it generates with all of the serial comms there.

James
I can repair or upgrade Megasquirts in UK. http://www.jamesmurrayengineering.co.uk

My Success story: http://www.msextra.com/forums/viewtopic ... 04&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
New users, please read the "Forum Help Page".
alk415
MS/Extra Newbie
Posts: 6
Joined: Tue Jun 21, 2016 7:45 am

Re: Microsquirt Serial Protocol Question

Post by alk415 »

jsmcortina wrote: Why do you think it is table 6? (It isn't.)

Taken from the microsquirt ini file in the 3.4.2 firmware files:
;Relationship between TS pages and MS2 pages
; See also ms2_extra_main_decls.h
;TS MS2 internal
;MS2 internal pages 0-3 are sensor lookup tables
;1 4
;2 5
;MS2 internal pages 6,7 are outpc,txbuf
;3 10
;4 8
;5 9
;6 11
;7 12
Seems to indicate that page 6 is ouptc to me. Though I guess I shouldn't be surprised about faulty MS documentation.

I didn't realize I could look at the comms log from Tunerstudio. I will definitely be making use of this feature, thanks!
Alfagta
Experienced MS/Extra'er
Posts: 239
Joined: Wed Aug 21, 2013 2:54 am

Re: Microsquirt Serial Protocol Question

Post by Alfagta »

6,7 outpc and txbuf vice versa....

thats a typo in the ini
Alfa 156 GTA
Alfa 75 Race Car MS III -- alway latest FW
Alfa 164 V6 Turbo
Alfa 155 2,5TD RIP
Test MS II --always latest FW
Tunerstudio V2.6.11 Registered
MegaLog Viewer V3.4.04 Registered
alk415
MS/Extra Newbie
Posts: 6
Joined: Tue Jun 21, 2016 7:45 am

Re: Microsquirt Serial Protocol Question

Post by alk415 »

Does anyone know if the update to Tunerstudio (v3) changed the communication startup sequence at all? I can't find anything in the changelogs that would indicate so...

I've upgraded recently and the initiation sequence on my controller stopped working. I will of course debug/figure it out, but I just wanna check and see if anyone ran into this problem yet
Alfagta
Experienced MS/Extra'er
Posts: 239
Joined: Wed Aug 21, 2013 2:54 am

Re: Microsquirt Serial Protocol Question

Post by Alfagta »

I dont think anything has changed according to this.
Turn on the Communication Debug log in TS and see whats in it.

BR
Alfa 156 GTA
Alfa 75 Race Car MS III -- alway latest FW
Alfa 164 V6 Turbo
Alfa 155 2,5TD RIP
Test MS II --always latest FW
Tunerstudio V2.6.11 Registered
MegaLog Viewer V3.4.04 Registered
Post Reply