From 898691e5ef922d90760d28c18f75b0284738a5b2 Mon Sep 17 00:00:00 2001 From: Piotr Esden-Tempski Date: Thu, 8 Nov 2012 15:21:40 -0800 Subject: [PATCH] Updated and backported improvements form the Lisa/M 2.0 CAN example. --- examples/stm32/f1/lisa-m-1/can/README | 4 ++++ examples/stm32/f1/lisa-m-1/can/can.c | 12 +++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 examples/stm32/f1/lisa-m-1/can/README diff --git a/examples/stm32/f1/lisa-m-1/can/README b/examples/stm32/f1/lisa-m-1/can/README new file mode 100644 index 00000000..3a14e3b1 --- /dev/null +++ b/examples/stm32/f1/lisa-m-1/can/README @@ -0,0 +1,4 @@ +This test sets up the CAN interface on Lisa/M and transmits 8 bites every +100ms. The first byte is being incremented in each cycle. The demo also +receives messages and is displaing the first 4 bits of the first byte on the +board LEDs. diff --git a/examples/stm32/f1/lisa-m-1/can/can.c b/examples/stm32/f1/lisa-m-1/can/can.c index 41432b60..a4cf30dc 100644 --- a/examples/stm32/f1/lisa-m-1/can/can.c +++ b/examples/stm32/f1/lisa-m-1/can/can.c @@ -106,15 +106,15 @@ void can_setup(void) rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_CANEN); - AFIO_MAPR = AFIO_MAPR_CAN1_REMAP_PORTB; + AFIO_MAPR |= AFIO_MAPR_CAN1_REMAP_PORTB; /* Configure CAN pin: RX (input pull-up). */ - gpio_set_mode(GPIOB, GPIO_MODE_INPUT, + gpio_set_mode(GPIO_BANK_CAN1_PB_RX, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_CAN1_PB_RX); gpio_set(GPIOB, GPIO_CAN1_PB_RX); /* Configure CAN pin: TX. */ - gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, + gpio_set_mode(GPIO_BANK_CAN1_PB_TX, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_CAN1_PB_TX); /* NVIC setup. */ @@ -165,8 +165,10 @@ void sys_tick_handler(void) static int temp32 = 0; static u8 data[8] = {0, 1, 2, 0, 0, 0, 0, 0}; - /* We call this handler every 1ms so 1000ms = 1s on/off. */ - if (++temp32 != 1000) + /* We call this handler every 1ms so 100ms = 1s + * Resulting in 100Hz message frequency. + */ + if (++temp32 != 100) return; temp32 = 0;