EmbDev.net

Forum: ARM programming with GCC/GNU tools data overrun


Author: Tom (Guest)
Posted on:

Rate this post
0 useful
not useful
Hey,
I am working with the LPC1768 and I have a problem with the Can 
implementation. Every message I received release a data overrun.
I don't know wants wrong with my code, it based on the examples from the 
nxp-Homepage.
/*****************************************************************************
* can.c: CAN module API file for NXP LPC17xx Family Microprocessors
*
* Copyright(C) 2009, NXP Semiconductor
* All rights reserved.
*
* History
* 2009.05.27 ver 1.00 Prelimnary version, first Release
* 13.10.2010 ver 1.1 Änderung bezüglich CAN2
*****************************************************************************/
#include "lpc17xx.h"
#include "type.h"
#include "can.h"
#include "mfa_display.h"

/* Receive Queue: one queue for each CAN port */
extern CAN_MSG MsgBuf_RX1;
extern volatile uint32_t CAN1RxDone;
extern volatile uint32_t kmph;
extern volatile uint32_t data[12];

volatile uint32_t CANStatus;
uint32_t CAN1RxCount = 0;
uint32_t CAN1ErrCount = 0;


/******************************************************************************
** Function name: CAN_ISR_Rx1
**
** Descriptions: CAN Rx1 interrupt handler
**
** parameters: None
** Returned value: None
**
******************************************************************************/
void CAN_ISR_Rx1( void )
{
uint32_t * pDest;


pDest = (uint32_t *)&MsgBuf_RX1;
*pDest = LPC_CAN1->RFS;

pDest++;
*pDest = LPC_CAN1->RID;


pDest++;
*pDest = LPC_CAN1->RDA;


pDest++;
*pDest = LPC_CAN1->RDB;

LPC_CAN1->CMR = 0x04; /* release receive buffer */
/*CAN1RxDone = TRUE;
return;
}

/*****************************************************************************
** Function name: CAN_Handler
**
** Descriptions: CAN interrupt handler
**
** parameters: None
** Returned value: None
**
*****************************************************************************/
void CAN_IRQHandler(void)
{
CAN_ISR_Rx1();
return;
}

/******************************************************************************
** Function name: CAN_Init
**
** Descriptions: Initialize CAN, install CAN interrupt handler
**
** parameters: bitrate
** Returned value: true or false, false if initialization failed.
**
******************************************************************************/
uint32_t CAN_Init( uint32_t can_btr )
{ CAN1RxDone = FALSE;

LPC_SC->PCONP |= ((1<<13)|(1<<14)); /* Enable CAN1 and CAN2 clock */

LPC_PINCON->PINSEL0 &= ~0x0000000F; /* CAN1 is p0.0 and p0.1 */
LPC_PINCON->PINSEL0 |= 0x00000005;

LPC_CAN1->MOD = LPC_CAN2->MOD = 1; /* Reset CAN */
LPC_CAN1->IER = LPC_CAN2->IER = 0; /* Disable Receive Interrupt */
LPC_CAN1->GSR = LPC_CAN2->GSR = 0; /* Reset error counter when CANxMOD is in reset */

LPC_CAN1->BTR = LPC_CAN2->BTR = can_btr;
LPC_CAN1->MOD = LPC_CAN2->MOD = 0x0; /* CAN in normal operation mode */

NVIC_EnableIRQ(CAN_IRQn);

LPC_CAN1->IER = LPC_CAN2->IER = 0x01; /* Enable receive interrupts */
return( TRUE );
}

/******************************************************************************
** Function name: CAN_SetACCF_Lookup
**
** Descriptions: unlock IDs
**
** parameters: none
** Returned value: none
**
******************************************************************************/
void CAN_SetACCF_Lookup( void )
{
uint16_t Id11_lo = 0x23;
uint16_t Id11_hi = 0x45;
uint32_t Id29_lo = 0x18DAF100;
uint32_t Id29_hi = 0x18DAF1FF;


uint32_t adr = 0;

LPC_CANAF->AFMR = ACCF_OFF; // Acceptance Filter OFF

LPC_CANAF->SFF_sa = adr;
*((volatile uint32_t *)(LPC_CANAF_RAM_BASE + adr)) = (Id11_lo << 16) | Id11_hi;
adr += 4;
LPC_CANAF->SFF_GRP_sa = adr;
LPC_CANAF->EFF_sa = adr;
LPC_CANAF->EFF_GRP_sa = adr;
LPC_CANAF->ENDofTable = adr;

return;
}

/******************************************************************************
** Function name: CAN_SetACCF
**
** Descriptions: Set acceptance filter and SRAM associated with
**
** parameters: ACMF mode
** Returned value: None
**
**
******************************************************************************/
void CAN_SetACCF( uint32_t ACCFMode )
{
switch ( ACCFMode )
{
case ACCF_OFF: /* Filter off*/
LPC_CANAF->AFMR = ACCFMode;
LPC_CAN1->MOD = LPC_CAN2->MOD = 1; // Reset CAN
LPC_CAN1->IER = LPC_CAN2->IER = 0; // Disable Receive Interrupt
LPC_CAN1->GSR = LPC_CAN2->GSR = 0; // Reset error counter when CANxMOD is in reset
break;

case ACCF_BYPASS: /* Bypass Mode --> all messages are accepted and stored */
LPC_CANAF->AFMR = ACCFMode;
break;

case ACCF_ON: /* hardware accepting filtering */
case ACCF_FULLCAN: /* hardware accepting filtering */
LPC_CANAF->AFMR = ACCF_OFF;
CAN_SetACCF_Lookup();
LPC_CANAF->AFMR = ACCFMode;
break;

default:
break;
}
return;
}




/*****************************************************************************
** Function name: main
**
** Descriptions: main routine for CAN module test
**
** parameters: None
** Returned value: int
**
*****************************************************************************/
int main( void )

{
SystemInit(); // Funktionsaufruf Systeminitialisierung
lcd_init();
INOUT_Def();

/* Please note, the bit timing is based on the setting of the
PCLK, if different PCLK is used, please read can.h carefully
and set your CAN bit timing accordingly. */

CAN_Init(BITRATE500K15MHZ); // Bitrate = 500kbaud bei 15MHz


MsgBuf_TX1.Frame = 0x00080000; // 11-bit, no RTR, DLC is 8 bytes
MsgBuf_TX1.MsgID = 0x2ee; // Explicit Standard ID
MsgBuf_TX1.DataA = data[0];
MsgBuf_TX1.DataB = data[1];

MsgBuf_RX1.Frame = 0x0;
MsgBuf_RX1.MsgID = 0x0;
MsgBuf_RX1.DataA = 0x0;
MsgBuf_RX1.DataB = 0x0;

CAN_SetACCF( ACCF_ON ); // Filtermodus festlegen

while ( 1 )
{

/* Transmit initial message on CAN 1 */
while ( !(LPC_CAN1->GSR & (1 << 3)) )
MsgBuf_TX1.DataA = data[0];
MsgBuf_TX1.DataB = data[1];
if ( CAN1_SendMessage( &MsgBuf_TX1 ) == FALSE )
{
continue;
}
lcd_draw_string(font_vw_16px, NORMAL_STYLE,"m/h",79,50,255);
kmph=(((data[1]>>14))&0b1111111111)*0.32;
if(kmph)
{
mph = kmph/(1.609);
char feld[12];
sprintf(feld,"%1u",mph);
lcd_draw_string(font_vw_16px, NORMAL_STYLE,feld,50,50,255);
}
else
{
lcd_draw_string(font_vw_16px, NORMAL_STYLE,"-.-",50,50,255);
}
/* please note: FULLCAN identifier will NOT be received as it's not set
in the acceptance filter. */
if ( CAN1RxDone == TRUE )
{
CAN1RxDone = FALSE;
MsgBuf_RX1.Frame = 0x0; // reset buffer
MsgBuf_RX1.MsgID = 0x0;
MsgBuf_RX1.DataA = 0x0;
MsgBuf_RX1.DataB = 0x0;
} /* Message on CAN 2 received */

/*Schalter = ((data[4]>>19)&TASTER_MASK); // Tasterauswertung
if(Schalter == 0x3)
{
LPC_GPIO2->FIOPIN &= ~(0x00000040);
}*/

if((MsgBuf_RX1.MsgID = 0x45)) // falls Nachricht mit entsprechenden Identifier da
{

LPC_GPIO2->FIOPIN &= ~(0x00000001); // setze LEDs
}

}

}




thanks for help

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.