pierremolinaro / acan-esp32

An ESP32 CAN 2.0B library
MIT License
40 stars 16 forks source link

Issues with format of the data in CMessage class #10

Open Marcel307 opened 7 months ago

Marcel307 commented 7 months ago

Hi, I am a bit new to this library and CAN in general. I have an ADXL357 accelerometer that give me 3 axis, each containing 8 Bytes of data, becausse the values are on type double. Now just for a small test I want to sent out each iteration one axis, in my case z. But it seems like the append() is setting the ok variable to false, not sending out any kind of data. On startup there is weird behaviour, because it tells me that the ok Variable is true, but the number of SentFrameCounts is not progressing more than just to the value of one.

So I am asking myself what the problem might be?

Snipplet out of the main File. This whole snipplet is written within a for-loop function iterating through the different sensors.

CANMessage frame;
            if(gSentFrameCountESP32 < MESSAGE_COUNT)
            {
            frame.id = 0x001F;                                             
            frame.len = 8;                                                   
            frame.data_s64 = z;                                            
            frame.rtr = false; 
            frame.ext = false;                  
            const bool ok = ACAN_ESP32::can.tryToSend(frame);              
            Serial.print("The Value of the ok variable is: ");
            Serial.println(ok);
            if(ok)
                {
                    gSentFrameCountESP32 =+ 1;                              
                }
            }   

            while(ACAN_ESP32::can.receive(frame))                        
            {       
                gReceivedFrameCountESP32 =+ 1;                            
            }
            Serial.print("Numbers of packets sent: "); 
            Serial.print(gSentFrameCountESP32);
        }
pierremolinaro commented 7 months ago

Hello,

You code seems ok. What is your network ? How do you configure the CAN module ? Is it alone in the network ? In normal mode, a CAN controller do not receive the frames it sends.

Pierre

Le 16 nov. 2023 à 13:57, Marcel307 @.***> a écrit :

Hi, I am a bit new to this library and CAN in general. I have an ADXL357 accelerometer that give me 3 axis, each containing 8 Bytes of data, becausse the values are on type double. Now just for a small test I want to sent out each iteration one axis, in my case z. But it seems like the append() is setting the ok variable to false, not sending out any kind of data. On startup there is weird behaviour, because it tells me that the ok Variable is true, but the number of SentFrameCounts is not progressing more than just to the value of one.

So I am asking myself what the problem might be?

Snipplet out of the main File. This whole snipplet is written within a for-loop function iterating through the different sensors.

CANMessage frame; if(gSentFrameCountESP32 < MESSAGE_COUNT) { frame.id = 0x001F;
frame.len = 8;
frame.data_s64 = z;
frame.rtr = false; frame.ext = false;
const bool ok = ACAN_ESP32::can.tryToSend(frame);
Serial.print("The Value of the ok variable is: "); Serial.println(ok); if(ok) { gSentFrameCountESP32 =+ 1;
} }

        while(ACAN_ESP32::can.receive(frame))                        
        {       
            gReceivedFrameCountESP32 =+ 1;                            
        }
        Serial.print("Numbers of packets sent: "); 
        Serial.print(gSentFrameCountESP32);
    }

— Reply to this email directly, view it on GitHub https://github.com/pierremolinaro/acan-esp32/issues/10, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEWKZVACYXKVQPHNC5U2NDTYEYESRAVCNFSM6AAAAAA7ODSOK6VHI2DSMVQWIX3LMV43ASLTON2WKOZRHE4TMOBQGEYDGOI. You are receiving this because you are subscribed to this thread.

Marcel307 commented 7 months ago

No the CAN Controller the Module is not alone in the Node. I am also using a another ESP32 and a another Module that supports CAN. Important to note is that the other ESP32 is using a another CAN lib. Before I testet this setup and it worked so that is confusing. And yes it is setup in normal mode. But I don`t know what exactly you mean with the configurement of the CAN module?

static const uint32_t DESIRED_BIT_RATE = 1000UL * 1000UL ; // 1 Mb
static uint32_t gBlinkLedDate = 0;
static uint32_t gReceivedFrameCountESP32 = 0 ;
static uint32_t gSentFrameCountESP32 = 0 ;
static const uint32_t MESSAGE_COUNT = 10 * 1000 ;

void setup()
{
settings.mRequestedCANMode = ACAN_ESP32_Settings::NormalMode ;  
settings.mRxPin = GPIO_NUM_33;                                 
settings.mTxPin = GPIO_NUM_32;                                  
const uint32_t errorCode = ACAN_ESP32::can.begin (settings) ;
.
.
.
}

Marcel

Marcel307 commented 7 months ago

Hello there, I have resolved my issues mentioned before. But now I have a other question. I want to send out the accel data of type double. If I want to send out the double data or add the type to the CANMessage class the frame will not be sent. Why is that?

Marcel

pierremolinaro commented 7 months ago

Hello,

The CANMessage class is defined in the CANMessage.h file : class CANMessage { public : uint32_t id = 0 ; // Frame identifier public : bool ext = false ; // false -> standard frame, true -> extended frame public : bool rtr = false ; // false -> data frame, true -> remote frame public : uint8_t idx = 0 ; // This field is used by the driver public : uint8_t len = 0 ; // Length of data (0 ... 8) public : union { uint64_t data64 ; // Caution: subject to endianness int64_t data_s64 ; // Caution: subject to endianness uint32_t data32 [2] ; // Caution: subject to endianness int32_t data_s32 [2] ; // Caution: subject to endianness float dataFloat [2] ; // Caution: subject to endianness uint16_t data16 [4] ; // Caution: subject to endianness int16_t data_s16 [4] ; // Caution: subject to endianness int8_t data_s8 [8] ; uint8_t data [8] = {0, 0, 0, 0, 0, 0, 0, 0} ; } ; } ;

If you want to add double, just add a field to the union :

public : union { uint64_t data64 ; // Caution: subject to endianness double data_double ; // Caution: subject to endianness int64_t data_s64 ; // Caution: subject to endianness uint32_t data32 [2] ; // Caution: subject to endianness int32_t data_s32 [2] ; // Caution: subject to endianness float dataFloat [2] ; // Caution: subject to endianness uint16_t data16 [4] ; // Caution: subject to endianness int16_t data_s16 [4] ; // Caution: subject to endianness int8_t data_s8 [8] ; uint8_t data [8] = {0, 0, 0, 0, 0, 0, 0, 0} ; } ;

For setting a double value : CANMessage message ; … message.data_double = a double value ;

Best regards,

Pierre

Le 21 nov. 2023 à 15:40, Marcel307 @.***> a écrit :

Hello there, I have resolved my issues mentioned before. But now I have a other question. I want to send out the accel data of type double. If I want to send out the double data or add the type to the CANMessage class the frame will not be sent. Why is that?

Marcel

— Reply to this email directly, view it on GitHub https://github.com/pierremolinaro/acan-esp32/issues/10#issuecomment-1821053104, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEWKZVBQ47ISLMQYDMLDJWTYFS4NTAVCNFSM6AAAAAA7ODSOK6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRRGA2TGMJQGQ. You are receiving this because you commented.