TX2 RX2... Am I missing something?

User avatar
Pito
Posts: 984
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: TX2 RX2... Am I missing something?

Postby Pito » Wed Aug 10, 2016 3:44 pm

The mapping is for example:

Code: Select all

MapleMini:
struct SEND_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to send
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  int blinks;   // or int32
  int pause;  // or int32
  short dummy;  // or int16
  long hallo;   // or int64
  char joe;   // or int8
};

Arduino Uno:
struct SEND_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to send
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  int32 blinks;
  int32 pause;
  int16 dummy;
  int64 hallo;
  char joe;  // or int8
};

Similar with unsigned.
Last edited by Pito on Wed Aug 10, 2016 3:46 pm, edited 1 time in total.
Pukao Hats Cleaning Services Ltd.

edogaldo
Posts: 242
Joined: Fri Jun 03, 2016 8:19 am

Re: TX2 RX2... Am I missing something?

Postby edogaldo » Wed Aug 10, 2016 3:46 pm

The library is for Arduino and in any case, in doubt, I'd try forcing the correct type size.

Nutsy
Posts: 214
Joined: Sun Jul 24, 2016 4:26 pm

Re: TX2 RX2... Am I missing something?

Postby Nutsy » Wed Aug 10, 2016 4:25 pm

Well that fixed it... Wrong data types... You see again I didnt know that Int had 16 32 64 bits.... On the maple mini i was able to force it to int16... arduino cant seem to force to the higher bit... I guess its the limitation of the hardware...

Anyway thats working now...
Thanks :D

Nutsy
Posts: 214
Joined: Sun Jul 24, 2016 4:26 pm

Re: TX2 RX2... Am I missing something?

Postby Nutsy » Wed Aug 10, 2016 5:25 pm

Spoke to soon... i could get the blink transfer program but im still having trouble sending data for my stepper motors to run on :/
All im sending are 2 ints... MPH and RPM :/

madias
Posts: 813
Joined: Mon Apr 27, 2015 11:26 am
Location: Vienna, Austria

Re: TX2 RX2... Am I missing something?

Postby madias » Thu Aug 11, 2016 8:57 pm

zmemw16 wrote:isn't maple i/o 5v tolerant?
isn't a high state for either side about 2v2 or is that just for ttl?

stephen

As I know all USART pins (NOT remapped and NOT USART2!) are 5v tolerant, so no level shifting is necessary. Rule of thumb (lazy man solution without pin out sheet): If a pin isn't ADC (or OSC,RTC) capture able it's 5v tolerant. But if you don't be sure and/or not be a member of the black magic smoke club, use things like this: http://joe-c.de/media/all/microC/STMF103RxTx_pinout.png
and yes: I didn't have any devices in my history which didn't recognized a 3.3v as "high"
I strongly suggest to use USART1 for every additional serial stuff, because these pins won't share anything you'll need maybe later (SPI, I2C...)

Nutsy
Posts: 214
Joined: Sun Jul 24, 2016 4:26 pm

Re: TX2 RX2... Am I missing something?

Postby Nutsy » Thu Aug 11, 2016 10:19 pm

Well i gave up on Easy Transfer and found a tutorial on how to send multiple values across serial to a second arduino...

It half works.

MPH dial is getting the correct numbers and runs as normal...
However the RPM one isnt working :( And I cant work out why.
I have a feeling its something to do with data types... Where the MPH dial only is getting numbers upto 80, the RPM is getting numbers up to 12000.

That should be within INTs range but ive set the variable to long just in case. But it still doesn't work.

Im really having a hard time getting this to work. Its stopping me from taking the project to the next level. I need to get these basic controls working before I can add real speed and rev calculating. I also want to get more creative with the LEDs... But I MUST get the dials to work.

Heres my project source....

http://hastebin.com/rodizuqibo.cs The Maple Mini side, does all the data heavy stuff

http://hastebin.com/docerabiha.cs The Mini Arduino Pro, is just reading off serial sent from the maple and controlling the motors.

Please take a look and tell me what I'm doing wrong? :(

User avatar
RogerClark
Posts: 5535
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: TX2 RX2... Am I missing something?

Postby RogerClark » Thu Aug 11, 2016 11:27 pm

I would start by printing the values to Serial USB. and see what is being set.

Then use software serial on the receiving end so that you can print what the receiver is actually receiving.

BTW. I suspect it would not be hard to get Easy Transfer to work, but you can't just have the same struct on the TX and RX side as the internal representations of the data will be different on 8 bit AVR and 32bit STM32, and the compiler is different which would possible result in different internal representation.

e.g. If you trued to send data using Easy Transfer from STM32 to another STM32 and used Keil as the compiler on the TX side and GCC on the RX side, there is a good chance the data would be screwed up and a different number of bytes.

If you are trsnasferring between systems that are more than 8 bits, you also have to deal with the "endian" ness of the processor its self, but in this case as the AVR is only 8 bits, the endian'ness is implemented by the compiler on the AVR side and will be determined by the hardware on the STM32 side
I have not double checked this , but STM32's seem to be little endian, and gcc AVR is also supposed to be little endian ( please double check this).


Of course as data types like float and double will also be an issue as they could be completely different on both sides. I know the AVR does not have double at all, as double is effectively type defed to float

User avatar
Pito
Posts: 984
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: TX2 RX2... Am I missing something?

Postby Pito » Fri Aug 12, 2016 12:10 am

You mess with types a lot in your code.
Why rpm an mph are long? Is the long the same on MM and Uno?
You are receiving a byte and you cast it to long or int - why? With serial.read() you get only 1 byte - which byte from "long" or int?
You cannot get the rpm and mph declared as long or int by reading a single byte from serial..
You do not use Easy Transfer within your code above..
With ET you may try:

Code: Select all

MMini:
struct SEND_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to send
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  uint16 RPM; // 0-20000
  uint16 MPH; // 0-5000 :)
};

ProMini:
struct RECEIVE_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to send
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  uint16 RPM;
  uint16 MPH;
};


When doing math with various types mind the casting might be necessary.
Also mind the ET does not care on synchronization (when you send and receive) and error handling during the transfer (it does a checksum via xor, but it does not request the data again when data received with error).
Pukao Hats Cleaning Services Ltd.

User avatar
RogerClark
Posts: 5535
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: TX2 RX2... Am I missing something?

Postby RogerClark » Fri Aug 12, 2016 12:44 am

BTW.

I'm going to merge the Serial TX buffering code into the master at the weekend (when I have time to double check the master will be OK)

This will speed up the transfers as it will no longer be blocking (but shouldn't cause you any problems, it should just make it faster)


Its interesting that you are using the Scheduler and that its working, as this is a relatively new feature to the Arduino API and I'm not sure many other people have used it on the STM32. Prior to the Scheduler in the API most people used FreeRTOS which is a much more powerful scheduling system, but in your case I suspect you could achieve the same scheduling using a switch statement

edogaldo
Posts: 242
Joined: Fri Jun 03, 2016 8:19 am

Re: TX2 RX2... Am I missing something?

Postby edogaldo » Fri Aug 12, 2016 7:42 am

I'd suggest you to change your formulas this way:

Code: Select all

long XYZm = (long)(dialRange * (((float)XYZv) / XYZRange));

This should better handle float to long roundings.

Best, E.

Nutsy wrote:Well i gave up on Easy Transfer and found a tutorial on how to send multiple values across serial to a second arduino...

It half works.

MPH dial is getting the correct numbers and runs as normal...
However the RPM one isnt working :( And I cant work out why.
I have a feeling its something to do with data types... Where the MPH dial only is getting numbers upto 80, the RPM is getting numbers up to 12000.

That should be within INTs range but ive set the variable to long just in case. But it still doesn't work.

Im really having a hard time getting this to work. Its stopping me from taking the project to the next level. I need to get these basic controls working before I can add real speed and rev calculating. I also want to get more creative with the LEDs... But I MUST get the dials to work.

Heres my project source....

http://hastebin.com/rodizuqibo.cs The Maple Mini side, does all the data heavy stuff

http://hastebin.com/docerabiha.cs The Mini Arduino Pro, is just reading off serial sent from the maple and controlling the motors.

Please take a look and tell me what I'm doing wrong? :(


Return to “Maple mini”

Who is online

Users browsing this forum: No registered users and 1 guest