Getting started with PCAN-RS-232

Programmable Converter for RS-232 to CAN
Post Reply
Mohamed
Posts: 3
Joined: Wed 9. Oct 2024, 17:02

Getting started with PCAN-RS-232

Post by Mohamed » Thu 10. Oct 2024, 08:33

Hello Everyone,
im quite frech and new here, also with the CAN-BUS topics. i took a new Pcan-RS-232 to test some IoT things.
My Converter will be connected via RS-232 to a Sensor (velocity) and transfer all via CAN.
I'm trying to flash the uC and intall the Firmware via CAN, putting the bridge between Ub and Boot pin and putting power (12V) to Ub, but the Software tool shows nothing.

could you please expplain step by step how to do that? would be nice ;)

kind regards,
RAMo

M.Maidhof
Support
Support
Posts: 1687
Joined: Wed 22. Sep 2010, 14:00

Re: Getting started with PCAN-RS-232

Post by M.Maidhof » Thu 10. Oct 2024, 11:37

Hello,

which PCAN PC interface do you use for the flash process? Do you use a terminated CAN cable between PCAN-RS232 and PCAN PC interface? For more details, please see info in the manual on page 18-23:

https://www.peak-system.com/produktcd/P ... an_eng.pdf

regards

Michael

Mohamed
Posts: 3
Joined: Wed 9. Oct 2024, 17:02

Re: Getting started with PCAN-RS-232

Post by Mohamed » Fri 11. Oct 2024, 08:45

Hello,

i used actually the serial alternative. it was the only option because i don't have a PCAN-USB to connect to my laptop.
i'll try to do it after with CAN-BUS to see if it works.

regards,
Ramo

M.Maidhof
Support
Support
Posts: 1687
Joined: Wed 22. Sep 2010, 14:00

Re: Getting started with PCAN-RS-232

Post by M.Maidhof » Mon 14. Oct 2024, 09:09

Hi,

you need a PCAN PC CAN interface for PEAK-Flash. A serial interface could not be used with PEAK-Flash.

https://www.peak-system.com/PC-Interfac ... .html?&L=1

regards

Michael

Mohamed
Posts: 3
Joined: Wed 9. Oct 2024, 17:02

Re: Getting started with PCAN-RS-232

Post by Mohamed » Fri 18. Oct 2024, 13:15

Thank you for replying. I'm trying to reed some data via RS232 in my laptop Terminal:
in my ser_to_can.c i have this code:

Code: Select all

#define __PCANRS232_C__


#include "LPC21xx.h"
#include "datatypes.h"
#include "hardware.h"
#include "systime.h"
#include "can.h"
#include "serial.h"
#include "ser_user.h"
#include "ser_to_can.h"
#include  <string.h>
#include  <stdio.h>



// RS232 parameters: 115200 bit/s, 8, N, 1
// CAN parameters: ID=0x123, DLC=8
// CAN bitrate: see can_init()
//
// Byte stream is received and converted to 8 byte CAN messages (ID=0x123).
// If nothing is received for more than 1 sec, the bytes already in the queue
// are transmitted onto CAN in a shorter message (DLC < 8). 
//
//*************************************************

void ShowRadarData(const char* data);


//*************************************************
// global data
//*************************************************
CANMsg_t  CanRxMsg, CanTxMsg;

// max. serial buffer length:
#define buflen (10) 			// 10 bytes max. by default

//u8_t	SerXmtBuf[buflen]; 		// will assemble and send telegram to the Host-PC / RS232
//u8_t	SerXmtBufPtr = 0;
u8_t	SerRcvBuf[buflen]; 		// holds received telegram from the Host-PC / RS232
u8_t	SerRcvBufPtr = 0;

u8_t    SerRcvTimeout_cnt;		// supervision timer

// status flags
u8_t SerRxOverrunOccurred;
u8_t SerTxCongestionOccurred;

void TransmitCanMessage(void);
//*************************************************



void PCANRS232_Init(void)
//*************************************************
//! @brief
//! Initializes software functions.
//! To be called from MAIN() once at module startup.
//!
//! @param	void
//!
//! @return	void
//!
//-------------------------------------------------
{
	// set led = uninitialized
	HW_SetLED (HW_LED_CAN1, HW_LED_RED); 	// OFF, GREEN, RED, ORANGE


	// --- initialize serial
    SER_UserInit (); 			// SER_BAUD_115K2
	SerRxOverrunOccurred = 0;				// reset error flags UART Rx
	SerTxCongestionOccurred = 0;			// reset error flags UART Tx
	SerRcvTimeout_cnt = SerRcvTimeout_max;  // reload supervision timer
	SerRcvBufPtr = 0;						// SER-TO-CAN direction
//	SerXmtBufPtr = 0;						// CAN-TO-SER direction (not used in this project)


	// --- initialize CAN
	//CAN_UserInit();

	// set led = initialized
	// HW_SetLED ( HW_LED_CAN1, HW_LED_GREEN); // OFF, GREEN, RED, ORANGE
}
//-------------------------------------------------



//-------------------RADAR DATA SEND --------------
void ShowRadarData(const char* data)
{
    SER_Write(SER_PORT1, (void*)data, strlen(data));
	//printf ("RADAR DATA: %s\n", data);
}
//-------------------------------------------------



void ProcessMsgFromSerial(void)
//*************************************************
//! @brief
//! reads telegrams from RS232 UART (Host-PC).
//! To be called from MAIN() loop, as fast as possible.
//!
//! Reads the incoming telegram from the host PC (RS232) 
//! and forwards it to CAN in 8-byte-packets.
//!
//! @param	void
//!
//! @return	void
//!
//-------------------------------------------------
{
	SERStatus_t ReadResult;
	u8_t CurRcvByte; 	// currently received byte from UART
	u8_t BytesRead;		// dummy parameter, must be supplied, but not used here

	
	do
	{
		// Read one byte from serial
		ReadResult = SER_Read (SER_PORT1, &CurRcvByte, 1, &BytesRead);
		

		// No bytes received, then ...
		if (ReadResult == SER_ERR_RX_EMPTY)
		{
			printf ("Reading Error: %d\n", ReadResult);
			//HW_SetLED(HW_LED_CAN1, HW_LED_RED);
			return;	 // ... quit, don't waste time here
		}
		//-------------------------------------------------
	    // Append received char into buffer
		if (ReadResult == SER_ERR_OK)
		{
			printf ("Received Byte: %02x\n", CurRcvByte);
			SerRcvBuf[SerRcvBufPtr] = CurRcvByte;		// append current byte to incoming telegram
			SerRcvBufPtr++;
			SerRcvTimeout_cnt = SerRcvTimeout_max;		// reload supervision timer
			HW_SetLED(HW_LED_CAN1, HW_LED_GREEN);

			if (SerRcvBufPtr >= CAN_DLC_MAX){
				SerRcvBuf[SerRcvBufPtr] = '\0';
				ShowRadarData((const char*)SerRcvBuf);
				SerRcvBufPtr = 0;
				//HW_SetLED(HW_LED_CAN1, HW_LED_GREEN);

			}
		}
		
		//-------------------------------------------------
	} // do
	while (SerRcvBufPtr < CAN_DLC_MAX); // until one CAN message is complete (8 bytes)

//	#####
//	At this point, one CAN message is complete (8 bytes)!
//	#####

	

}
//-------------------------------------------------




void ProcessTimer25msec(void)
//*************************************************
//! @brief
//!
//! Called every 25msec from MAIN().
//!
//! @param	void
//!
//! @return	void
//!
//-------------------------------------------------
{
	// Here we are counting down the 1 sec supervision timer.
	// If nothing is received from SER within 1 sec., 
	// a shorter CAN message will be sent anyway.
	// if (SerRcvTimeout_cnt > 0) SerRcvTimeout_cnt--;
	// else // timed out
	// {
	// 	if (SerRcvBufPtr > 0) TransmitCanMessage(); // Send, if DLC > 0
	// 	SerRcvTimeout_cnt = SerRcvTimeout_max; // reload supervision timer
	// }
}
/**************************************************/


in the main.c

Code: Select all

#include "LPC21xx.h"
#include "datatypes.h"
#include "systime.h"
#include "hardware.h"
#include "crc_data.h"
#include "ser_to_can.h"
#include "serial.h"



// Global variables
u32_t 	SerRcvTimeout = 0;
u32_t 	TimeDiff1000Hz = 0;
u32_t 	TimeDiffLed = 0;
u32_t 	TimeDiff25ms = 0;

u8_t	DeviceID;			// Holds PCAN-RS-232 device ID from solder jumpers


void ShowRadarData(const char* data);


int main (void)
{
	HW_Init();
	SYSTIME_Init();

	// Get PCAN-RS-232 device ID from internal solder jumpers
	HW_GetModuleID (&DeviceID); // not used herein

	PCANRS232_Init(); // Initializes Device (incl. CAN and RS232 interfaces)

	TimeDiff25ms=SYSTIME_NOW;

	// main loop
	while (1)
	{
		//-------------------------------------------------
		// call every 25msec (for doing cyclic things ...)
		if (SYSTIME_DIFF (TimeDiff25ms, SYSTIME_NOW) > 25000)
		{
			TimeDiff25ms=SYSTIME_NOW;
			//ProcessTimer25msec(); // do cyclic stuff herein...
			ProcessMsgFromSerial();
		}
		//-------------------------------------------------

		// 1Hz LED Blinker (500 msec on, 500 msec off)
		// if (SYSTIME_DIFF (TimeDiffLed, SYSTIME_NOW) > 500000)
		// {
		// 	TimeDiffLed = SYSTIME_NOW;

		// 	// toggle LED
		// 	if (BlinkState != HW_LED_GREEN)
		// 	{
		// 		BlinkState = HW_LED_GREEN;
		// 	}
		// 	else
		// 	{
		// 		BlinkState = HW_LED_OFF;
		// 	}
		// 	HW_SetLED (HW_LED_CAN1, BlinkState);
		// }//IF: SYSTIME_DIFF
		//-------------------------------------------------
		//ProcessMsgFromSerial(); // read messages coming in from RS232 UART
	}
}
it doesn't work, the RED_LED is permanently ON and in the Terminal i see no Data. Any Help?

M.Heidemann
Sales & Support
Sales & Support
Posts: 1023
Joined: Fri 20. Sep 2019, 13:31

Re: Getting started with PCAN-RS-232

Post by M.Heidemann » Fri 18. Oct 2024, 15:29

Hello,

If that's 1:1 the same code that you run i wouldn't expect the LED to do anything,
the whole section handling the LED states is commented out (//)...

Can you check, if that's the case with your current code as well?

BR

Marv
---
Marvin Heidemann
PEAK-Support Team

Post Reply