All pastes #245234 Raw Edit

arune

public c v1 · immutable
#245234 ·published 2006-11-10 19:13 UTC
rendered paste body
/** * CAN test program. *  * @target	AVR * @date	2006-10-29 * @author	Jimmy Myhrman *    *//*----------------------------------------------------------------------------- * Includes *---------------------------------------------------------------------------*//* system files */#include <avr/io.h>#include <avr/interrupt.h>#include <avr/wdt.h>#include <stdio.h>/* lib files */#include <can.h>#include <timebase.h>#include <protocol.h>/*----------------------------------------------------------------------------- * Main Program *---------------------------------------------------------------------------*/int main(void) {	TimebaseInit();	UartInit();	sei();		printf("\n------------------------------\n");	printf("   CAN Monitor\n");	printf("------------------------------\n");		printf("CanInit...");	if (CanInit(CAN_BITRATE_1M) != CAN_OK) {		printf("FAILED!\n");	}	else {		printf("OK!\n");	}		uint32_t timeStamp = 0;		CanMessage_t txMsg;	CanMessage_t rxMsg;		txMsg.DataLength = 8;	txMsg.Data.bytes[0] = 7;	txMsg.Id = 733;	txMsg.RemoteFlag = 0;	txMsg.ExtendedFlag = 1;		/* main loop */	while (1) {		/* any new CAN messages received? */		if (CanReceive(&rxMsg) == CAN_OK) {			ProtocolParseCanMessage(&rxMsg);						uart_puthex_byte((uint8_t)(rxMsg.Id>>24));			uart_puthex_byte((uint8_t)(rxMsg.Id>>16));			uart_puthex_byte((uint8_t)(rxMsg.Id>>8));			uart_puthex_byte((uint8_t)rxMsg.Id);			uart_puts(" ");						uint8_t i;			for (i = 0; i < rxMsg.DataLength; i++) {				uart_puthex_byte((uint8_t)rxMsg.Data.bytes[i]);			}			uart_puts("\n");		}				/* send CAN message and check for CAN errors once every second */		if (TimebasePassedTimeMS(timeStamp) >= 1000) {			/* increase ID and send txMsg */			txMsg.Id++;			CanSend(&txMsg);			/* check for errors */			timeStamp = TimebaseCurrentTime();			if (CanCheckError() != CAN_OK) {				printf("CAN ERROR detected!\n");			}		}	}		return 0;}