Basic can bus example with LCD hint

Dependencies:   BSP_DISCO_F429ZI LCD_DISCO_F429ZI TS_DISCO_F429ZI mbed

Committer:
tamirci
Date:
Sun Dec 31 21:49:17 2017 +0000
Revision:
0:6d192735c003
Initial Release; LED lights on during transmission however TTL level signals are not captured correctly

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tamirci 0:6d192735c003 1 /******************************************************
tamirci 0:6d192735c003 2 * by tamirci::156103010::ST
tamirci 0:6d192735c003 3 * STM32F429I-DISCO Board Can Bus Example
tamirci 0:6d192735c003 4 *
tamirci 0:6d192735c003 5 * CAN1_RX -> PD_0, CAN1_TX -> PD_1
tamirci 0:6d192735c003 6 * LED1 -> PG_13, LED2 -> PG14
tamirci 0:6d192735c003 7 *
tamirci 0:6d192735c003 8 ******************************************************/
tamirci 0:6d192735c003 9 #include "mbed.h"
tamirci 0:6d192735c003 10 #include "TS_DISCO_F429ZI.h"
tamirci 0:6d192735c003 11 #include "LCD_DISCO_F429ZI.h"
tamirci 0:6d192735c003 12
tamirci 0:6d192735c003 13 Ticker ticker; // timer object for periodic transmission
tamirci 0:6d192735c003 14 DigitalOut led1(LED1); // GPIO object for LED indication of can tx event
tamirci 0:6d192735c003 15 DigitalOut led2(LED2); // GPIO object for LED indication of can rx event
tamirci 0:6d192735c003 16 CAN can1(PD_0, PD_1); // CAN tranmit object::ttl level waves can be captured
tamirci 0:6d192735c003 17 LCD_DISCO_F429ZI lcd; // Just to be sure demo application firmware is running
tamirci 0:6d192735c003 18
tamirci 0:6d192735c003 19 char counter = 0; // the value that will be transmitted
tamirci 0:6d192735c003 20
tamirci 0:6d192735c003 21 void send() {
tamirci 0:6d192735c003 22 printf("send()\n");
tamirci 0:6d192735c003 23 if(can1.write(CANMessage(1337, &counter, 1))) {
tamirci 0:6d192735c003 24 printf("wloop()\n");
tamirci 0:6d192735c003 25 counter++;
tamirci 0:6d192735c003 26 printf("Message sent: %d\n", counter);
tamirci 0:6d192735c003 27 }
tamirci 0:6d192735c003 28 led1 = !led1;
tamirci 0:6d192735c003 29 }
tamirci 0:6d192735c003 30
tamirci 0:6d192735c003 31 int main() {
tamirci 0:6d192735c003 32
tamirci 0:6d192735c003 33 CANMessage msg;
tamirci 0:6d192735c003 34 BSP_LCD_SetFont(&Font20);
tamirci 0:6d192735c003 35 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"CAN BUS", CENTER_MODE);
tamirci 0:6d192735c003 36 lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"EXAMPLE", CENTER_MODE);
tamirci 0:6d192735c003 37 lcd.DisplayStringAt(0, LINE(7), (uint8_t *)"156103010", CENTER_MODE);
tamirci 0:6d192735c003 38 lcd.DisplayStringAt(0, LINE(8), (uint8_t *)"ST", CENTER_MODE);
tamirci 0:6d192735c003 39 wait(1);
tamirci 0:6d192735c003 40 printf("main()\n");
tamirci 0:6d192735c003 41 ticker.attach(&send,1); // send can message over CAN1_TX
tamirci 0:6d192735c003 42 while(1) {
tamirci 0:6d192735c003 43 printf("loop()\n");
tamirci 0:6d192735c003 44 if(can1.read(msg)) {
tamirci 0:6d192735c003 45 printf("Message received: %d\n", msg.data[0]);
tamirci 0:6d192735c003 46 led2 = !led2;
tamirci 0:6d192735c003 47 }
tamirci 0:6d192735c003 48 wait(0.2);
tamirci 0:6d192735c003 49 }
tamirci 0:6d192735c003 50 }