TX2 RX2... Am I missing something?

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

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

Post by RogerClark » Fri Aug 12, 2016 10:00 pm

Re: transfer via I2C to AVR

Last time I tried this, it didnt work because of a bug in the Arduino AVR core code that had not been fixed for years. I eventually found the fix on the Arduino.cc forum and had to edit the AVR core.

But I suppose they may have fixed that bug by now.


However as you are not sending much data, Serial would probably be fine and requires less components ( no level shifting).

You could also look at how often you send updates to the display. I doubt you need to update it that often, and if you want animation, you could interpolate results on the AVR side to give the appearance of a higher frame rate.


Re: Endianness

Processors are Big Endian or Small Endian.
Its a way to describe how the processor internally stores numbers

e.g. Whether the processor stores 0x1234 in memory

0x12
0x34


or

0x34
0x12

which is further complicated if the processor is 16 bit, as 0x12345678 could be stored as

0x5678
0x1234

so in memory as single bytes would be

0x56
0x78
0x12
0x34

( Google and you will find much better explanations)

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

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

Post by madias » Sat Aug 13, 2016 9:13 am

ok, sorry for getting OT here, Roger: Do you mean this one? http://dsscircuits.com/articles/86-arti ... er-library

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

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

Post by madias » Sat Aug 13, 2016 9:16 am

Another thing (to be on topic) with serial is, that you have always do a "Serial.available", cause it's not interrupt driven by library. It's not a real issue but have have to take care of it. A simple solution would be (on STM32, because you have more timers you evermostly need) to set the "Serial.available" into a timer triggered interrupt and give back a flag.

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

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

Post by RogerClark » Sat Aug 13, 2016 10:31 am

Sorry Matthias

I can't really remember exactly what the problem was.

I know that I had to write an I2C Slave to SPI bridge using a Pro Mini, but when I first tried my code it didn't work.

But when I investigated the problem the fix was to actually change something the I2C library of the AVR
This was probably 1 year or possibly more ago and perhaps it now works fine

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

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

Post by Nutsy » Sat Aug 13, 2016 3:40 pm

Im not sure whats going on any more :( Both MPH and RPM arent working again... I have tried several things but I even reverted to some older code and it still doesnt work.......

the figures I'm sending out are int16, and are correct up to the point of serial write.
But on the arduino the returned figures are completely wrong. Numbers, but in no way the correct numbers... Im even getting minus values.

I have tried several type conversions and its all the same... Ive tried everything I can think of. I honestly dont know what to do

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

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

Post by madias » Sat Aug 13, 2016 4:53 pm

Nutsy, again: Are you really sure, that you have a common ground STM32 <---> Arduino?

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

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

Post by edogaldo » Sat Aug 13, 2016 5:03 pm

Nutsy wrote:Im not sure whats going on any more :( Both MPH and RPM arent working again... I have tried several things but I even reverted to some older code and it still doesnt work.......

the figures I'm sending out are int16, and are correct up to the point of serial write.
But on the arduino the returned figures are completely wrong. Numbers, but in no way the correct numbers... Im even getting minus values.

I have tried several type conversions and its all the same... Ive tried everything I can think of. I honestly dont know what to do
It's difficult to support if we don't know your changes..

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

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

Post by Nutsy » Sat Aug 13, 2016 5:12 pm

Hi , sorry yeah common ground.
As for changes. Tbh I couldnt really work out how much i changed :p

Anyway, ive regrabbed my code from the hastebin posts and the MPH is working again. So its not hardware failure... I now need to look through it very closely to see what broke it and what fixed it...

I still think the issue is down to data types
ill start going over it again now...

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

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

Post by edogaldo » Sat Aug 13, 2016 5:16 pm

Nutsy wrote:Hi , sorry yeah common ground.
As for changes. Tbh I couldnt really work out how much i changed :p

Anyway, ive regrabbed my code from the hastebin posts and the MPH is working again. So its not hardware failure... I now need to look through it very closely to see what broke it and what fixed it...

I still think the issue is down to data types
ill start going over it again now...
Did you try applying the formula changes at leasr for rpm? It should fix it.

Best, E.

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

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

Post by Pito » Sat Aug 13, 2016 5:31 pm

Here is an Example - Send and Receive via Easy Transfer with a single Mini.
Connect RX1 with TX1, watch usb serial console.
You may experiment with the cable's lenghts and serial speeds :)
PS: using stm32duino core with TX buffer implemented..

Code: Select all

// Example - Easy Transfer running on a single MapleMini/BluePill
// ET data channel - Connect RX1 with TX1
// For results watch usb serial console
// Pito 8/2016

#include <EasyTransfer.h>
//create two objects
EasyTransfer ETin, ETout; 
struct RECEIVE_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to receive
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  int rpm;
  int mph;
};
struct SEND_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to receive
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  int rpm;
  int mph;
};
//give a name to the group of data
RECEIVE_DATA_STRUCTURE rxdata;
SEND_DATA_STRUCTURE txdata;

void setup(){

  Serial.begin(115200);  // usb console  
  
  Serial1.begin(1382400); // Easy Transfer data channel, connect RX1 and TX1 together
 
  //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
  ETin.begin(details(rxdata), &Serial1);
  ETout.begin(details(txdata), &Serial1);
 }
  
void loop() {
  
  //first, lets read rpm and mph
  txdata.rpm = 12666;
  txdata.mph = 187;  
  
  // then we will go ahead and send that data out
  ETout.sendData();
  
  // and we receive the same data
    rxdata.rpm = 0;
    rxdata.mph = 0;
    ETin.receiveData();
    
  // we print out what we received  
    Serial.print(rxdata.rpm);
    Serial.print("  ");
    Serial.print(rxdata.mph);    
    
    if ((rxdata.rpm != txdata.rpm) || (rxdata.mph != txdata.mph)){
      Serial.println("   ERROR");
    } else {
      Serial.println("   OK");
    }   
    
  delay(100);
}

Code: Select all

12666  187   OK
12666  187   OK
12666  187   OK
12666  187   OK
12666  187   OK
12666  187   OK
12666  187   OK
Pukao Hats Cleaning Services Ltd.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest