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?