Content originally posted in LPCWare by MAUROFIUNER on Tue Nov 13 12:46:14 MST 2012
I'm trying to send a messagge with LCPXpresso-LPC1769,but I can´t..
I don´t know why signal go down when should maintain high.
Excuse my bad English!
My code is:
#include "lpc17xx_can.h"
#include "lpc17xx_libcfg.h"
#include "lpc17xx_pinsel.h"
#include "debug_frmwrk.h"
#include "lpc17xx_gpio.h"
/* Example group ----------------------------------------------------------- */
/** @defgroup CAN_LedControlCAN_LedControl
* @ingroup CAN_Examples
* @{
*/
/************************** PRIVATE VARIABLES *************************/
uint8_t menu[]=
"*******************************************************************************\n\r"
"Hello NXP Semiconductors \n\r"
"CAN demo \n\r"
"\t - MCU: LPC17xx \n\r"
"\t - Core: ARM CORTEX-M3 \n\r"
"\t - Communicate via: UART0 - 115200 bps \n\r"
"Use two CAN peripherals: CAN1 and CAN2 to communicate\n\r"
"Use CAN frames to control LED display\n\r"
"*******************************************************************************\n\r";
/** CAN variable definition **/
CAN_MSG_Type TXMsg, RXMsg; // messages for test Bypass mode
uint8_t LED_Value;
uint32_t LED[8] = {(1<<6),(1<<5),(1<<4),(1<<3),(1<<2),(1<<31),(1<<29),(1<<28)};
/************************** PRIVATE FUNCTIONS *************************/
void CAN_IRQHandler(void);
void CAN_InitMessage(void);
//void print_menu();
/*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/
/*********************************************************************//**
* @briefCAN_IRQ Handler, control receive message operation
* param[in]none
* @return none
**********************************************************************/
void CAN_IRQHandler()
{
uint8_t IntStatus;
uint32_t data,i;
/* get interrupt status
* Note that: Interrupt register CANICR will be reset after read.
* So function "CAN_IntGetStatus" should be call only one time
*/
IntStatus = CAN_IntGetStatus(LPC_CAN2);
//check receive interrupt
if((IntStatus>>0)&0x01)
{
CAN_ReceiveMsg(LPC_CAN2,&RXMsg);
data = RXMsg.dataA[0];
for(i=0;i<8;i++)
{
if ((data >> i)&0x01)
{
if(i<5)
GPIO_SetValue(2,LED);
else
GPIO_SetValue(1,LED);
}
else
{
if(i<5)
GPIO_ClearValue(2,LED);
else
GPIO_ClearValue(1,LED);
}
}
}
}
/*-------------------------PRIVATE FUNCTIONS----------------------------*/
/*********************************************************************//**
* @briefInitialize transmit and receive message for Bypass operation
* @param[in]none
* @return none
**********************************************************************/
void CAN_InitMessage(void) {
TXMsg.format = STD_ID_FORMAT;
TXMsg.id = 0x7ff;
TXMsg.len = 8;
TXMsg.type = DATA_FRAME;
TXMsg.dataA[0] = TXMsg.dataA[1] = TXMsg.dataA[2] = TXMsg.dataA[3] = 0xffffffff;
TXMsg.dataB[0] = TXMsg.dataB[1] = TXMsg.dataB[2] = TXMsg.dataB[3] = 0xffffffff;
RXMsg.format = 0x00;
RXMsg.id = 0x00;
RXMsg.len = 0x00;
RXMsg.type = 0x00;
RXMsg.dataA[0] = RXMsg.dataA[1] = RXMsg.dataA[2] = RXMsg.dataA[3] = 0x00000000;
RXMsg.dataB[0] = RXMsg.dataB[1] = RXMsg.dataB[2] = RXMsg.dataB[3] = 0x00000000;
}
/*-------------------------MAIN FUNCTION------------------------------*/
/*********************************************************************//**
* @briefc_entry: Main CAN program body
* @param[in]none
* @return int
**********************************************************************/
int c_entry(void) { /* Main Program */
PINSEL_CFG_Type PinCfg;
/* LED setting */
GPIO_SetDir(1,(1<<28)|(1<<29)|(1<<31),1);
GPIO_SetDir(2,(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6),1);
/* Pin configuration
*CAN1: select 0.0 as RD1. P0.1 as TD1
*/
PinCfg.Funcnum = 1;
PinCfg.OpenDrain = 0;
PinCfg.Pinmode = 0;
PinCfg.Pinnum = 0;
PinCfg.Portnum = 0;
PINSEL_ConfigPin(&PinCfg);
PinCfg.Pinnum = 1;
PINSEL_ConfigPin(&PinCfg);
// CAN2 Pins P0.4 as RD2 and P0.5 as TD2
PinCfg.Funcnum = 2;
PinCfg.Pinnum = 4;
PinCfg.Portnum = 0;
PINSEL_ConfigPin(&PinCfg);
PinCfg.Pinnum = 5;
PINSEL_ConfigPin(&PinCfg);
//Initialize CAN1 & CAN2
CAN_Init(LPC_CAN1, 125000);
CAN_Init(LPC_CAN2, 125000);
//Enable Interrupt
CAN_IRQCmd(LPC_CAN2, CANINT_RIE, ENABLE);
CAN_SetAFMode(LPC_CANAF,CAN_AccBP);
CAN_InitMessage();
//Enable CAN Interrupt
NVIC_EnableIRQ(CAN_IRQn);
while(1)
{//receiving is done via interrupt
//CAN_SendMsg(LPC_CAN1, &TXMsg);
CAN_SendMsg(LPC_CAN2, &TXMsg);
}
return 1;
}
#if 0
/* With ARM and GHS toolsets, the entry point is main() - this will
allow the linker to generate wrapper code to setup stacks, allocate
heap area, and initialize and copy code and data segments. For GNU
toolsets, the entry point is through __start() in the crt0_gnu.asm
file, and that startup code will setup stacks and data */
int main(void) {
return c_entry();
}
#endif
#ifdef DEBUG
/*******************************************************************************
* @briefReports the name of the source file and the source line number
* where the CHECK_PARAM error has occurred.
* @param[in]file Pointer to the source file name
* @param[in] line assert_param error line source number
* @returnNone
*******************************************************************************/
void check_failed(uint8_t *file, uint32_t line) {
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
;
}
#endif
Oscilloscope Capture is: