# Can Bus exemple

**URL:** <https://discuss.px4.io/t/can-bus-exemple/24426>\
**Category:** Uncategorized\
**Created:** [October 3, 2021, 7:47pm UTC](https://discuss.px4.io/t/can-bus-exemple/24426 "2021-10-03T19:47:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DiaZ0te](https://discuss.px4.io/letter_avatar_proxy/v4/letter/d/65b543/32.png) [@DiaZ0te](https://discuss.px4.io/u/DiaZ0te)\
**Post date:** [October 3, 2021, 7:47pm UTC](https://discuss.px4.io/t/can-bus-exemple/24426/1 "2021-10-03T19:47:10Z")

</div>

Hi !

As part of using px4 on a classic can bus machine. I would like to use the can bus to communicate with the rest of my components.

By taking the NuttX example on the can bus, I get a compilation error.  
Here is my code, they are in src / module :

can\_pilot.cpp :

```auto
#include "can_pilot.hpp"
#include <fcntl.h>
#include <poll.h>

#include <nuttx/can/can.h>
#include <arch/board/board.h>

#include "stm32_can.h"

#include <px4_platform_common/log.h>

/ ********************************************************************************
 * Variables globales
 ******************************************************************************** /

 / ********************************************************************************
 * Fonction INIT
 ******************************************************************************** /

int init_can(){
	struct can_dev_s *can = stm32_caninitialize(1);

	if (can == nullptr) {
		PX4_ERR("Failed to get CAN interface");

	} else {
		/* Register the CAN driver at "/dev/can0" */
		int ret = can_register("/dev/can0", can);

		if (ret < 0) {
			PX4_ERR("can_register failed: %d", ret);

		} else {
			_fd = ::open("/dev/can0", O_RDWR | O_NONBLOCK);
		}
	}

	return 0;
}

```

can\_pilot.hpp :

```auto

#include <nuttx/config.h>
#include <px4_platform_common/px4_config.h>

/ ********************************************************************************
 * Fonctions proto
 ******************************************************************************** /
int init_can();

void can_send();
void can_read();

```

Here is my error message:

 ![Capture d’écran de 2021-10-03 21-44-54](https://discuss.px4.io/uploads/default/original/2X/6/632f2afa0afa48a484285733ab988c7c76dd8b73.png)

I really hope you have an idea to help me out.

Best regards.
