Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

Olimex TMS570-CAN board - CAN1 and CAN2 loopback

$
0
0

Hello, I used the example of HALCoGen: 03.05.00 and created the Projects:
/ ** @ Example example_canCommunication.c
* This is an example which describes the steps to create an example application which
* Configures two can nodes 1 and 2 and starts a communication with a sample data chunk.
* CAN 1 and CAN2 must be part of CAN network
*
*
* @ B Step @ b 1:
*
* Create a new project.
*
* Navigate: -> File -> New -> Project
*
* @ Image html example_createProject.jpg "Figure: Create a new Project"
*
* @ B Step @ b 2:
*
* Configure driver code generation:
* - Enable can driver
* - Disable others
*
* Navigate: -> TMS570LSxx / RM4 -> Enable Drivers
*
* @ Image html can_enabledriver.JPG "Figure: Enable CAN Driver"
*
* @ B Step @ b 3:
*
* Configure CAN Baudrate:
*
* Navigate: -> TMS570LSxx / RM4 -> CAN
*
* @ Image html can1baud.JPG "Figure: CAN1 BaudRate Configuration"
* @ Image html can2baud.JPG "Figure: CAN2 BaudRate Configuration"
*
* @ B Step @ b 4:
*
* Configure CAN MessageBox:
*
* - Configure CAN1, MessageBox 1 - Activate and Enable TX
* - Configure CAN2, MessageBox 1 - Activate and Enable RX
*
* Navigate: -> TMS570LSxx / RM4 -> CAN
*
* @ Image html canCommunication1.JPG "Figure: CAN1 MBox Configuration"
* @ Image html canCommunication2.JPG "Figure: CAN2 MBox Configuration"
*
* @ B Step @ b 5:
*
* Copy the source code below into your sys_main.c or replace sys_main.c with this file.
*
* The example file can also be found in the examples folder: .. / HALCoGen / examples
*
* @ Note HALCoGen generates an empty main function in sys_main.c,
*
* /

/ * USER CODE BEGIN (0) * /
/ * USER CODE END * /

/ * Include Files * /

# Include "sys_common.h"
# Include "system.h"

/ * USER CODE BEGIN (1) * /
# Include "can.h"

/ * Include ESM header file - types, definitions and function declarations for system driver * /
# Include "esm.h"

# Define D_SIZE 9

uint8 tx_data [D_SIZE] = {'H', 'E', 'R', 'C', 'U', 'L', 'E', 'S', '\ 0'};
uint8 rx_data [D_SIZE] = {0};
uint32 error = 0;

uint32 checkPackets (uint8 * src_packet, uint8 * dst_packet, uint32 psize);
/ * USER CODE END * /


/ ** @ Fn void main (void)
* @ Brief Application main function
*
* /

/ * USER CODE BEGIN (2) * /
/ * USER CODE END * /


void main (void)
{
/ * USER CODE BEGIN (3) * /

    / * Initialize can 1 and 2 * /
    canInit (); / * can1 -> can2 * /

    / * Transmit on can1 * /
    canTransmit (canREG1, canMESSAGE_BOX1, tx_data);

    / * ... wait until message receive on can2 * /
    while (! canIsRxMessageArrived (canREG2, canMESSAGE_BOX1));
    canGetData (canREG2, canMESSAGE_BOX1, rx_data); / * receive on can2 * /

    / * Check received data patterns * /
    error = checkPackets (& tx_data [0], & rx_data [0], D_SIZE);

    / * ... run forever * /
    while (1);

/ * USER CODE END * /
}

/ * USER CODE BEGIN (4) * /
/ ** @ Fn checkPackets (uint8 * src_packet, uint8 * dst_packet, uint32 psize)
* @ Brief check two buffers and report error
*
* /
uint32 checkPackets (uint8 * src_packet, uint8 * dst_packet, uint32 psize)
{
   uint32 err = 0;
   uint32 cnt = psize;

   while (cnt -)
   {
     if ((* src_packet + +)! = (* dst_packet + +))
     {
        err + +; / * data error * /
     }
   }
   return (err);
}
/ * USER CODE END * /

I'm on the board are connected:
CAN1 (CH) <-> CAN2 (CH)
CAN1 (CL) <-> CAN2 (CL)

And run the code in the input buffer "rx_data" data is not updated, I do not know what the problem is ....


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>