Skip to content

Can receive returns empty bytes, Can send doesnt send. #145

Closed
@illegal-instruction-co

Description

@illegal-instruction-co

I have got UNO R3 ( original one ) and seeed studio can shield v2.

This is my code:

#include "Config.h"

#include "Components/Logger.h"
#include "Components/Can.h"

#include <SPI.h>

namespace ii::blackbox::components {

void Can::SetUp() {
	// m_canSend.setMode(CAN_NORMAL_MODE);
	// m_canSend.setMode(CAN_NORMAL_MODE);

	while (m_canSend.begin(CAN_500KBPS) != CAN_OK && m_canReceive.begin(CAN_500KBPS) != CAN_OK) {
#ifdef SERIAL_DEBUG
		SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
#endif
		delay(100);
	}

#ifdef SERIAL_DEBUG
	SERIAL_PORT_MONITOR.println("CAN init OK.");
#endif
}

unsigned char len = 0;
unsigned char buf[8];

void Can::Loop() {
	// ---------------------

	if (CAN_MSGAVAIL == m_canReceive.checkReceive()) {
		// read data,  len: data length, buf: data buf
		SERIAL_PORT_MONITOR.println("checkReceive");
		m_canReceive.readMsgBuf(&len, buf);
		// print the data
		SERIAL_PORT_MONITOR.print("ID: ");
		SERIAL_PORT_MONITOR.print(m_canReceive.getCanId());
		SERIAL_PORT_MONITOR.print("  DLC: ");
		SERIAL_PORT_MONITOR.print(len);
		for (int i = 0; i < len; i++) {
			// SERIAL_PORT_MONITOR.print(buf[i]);
			// SERIAL_PORT_MONITOR.print(" ");
		}
		SERIAL_PORT_MONITOR.println();
	}
	SERIAL_PORT_MONITOR.println("---LOOP END---");
}

} // namespace ii::blackbox::components

and here is the response:

checkReceive
ID: 536870911  DLC: 255
---LOOP END---
checkReceive
ID: 536870911  DLC: 255
---LOOP END---
checkReceive
ID: 536870911  DLC: 255
---LOOP END---
checkReceive
ID: 536870911  DLC: 255
---LOOP END---
checkReceive
ID: 536870911  DLC: 255
---LOOP END---
checkReceive
ID: 536870911  DLC: 255
---LOOP END---
checkReceive
ID: 536870911  DLC: 255
---LOOP END---
checkReceive
ID: 536870911  DLC: 255
---LOOP END---
checkReceive
ID: 536870911  DLC: 255
---LOOP END---
checkReceive
ID: 536870911  DLC: 255
---LOOP END---
checkReceive
ID: 536870911  DLC: 255
---LOOP END---
checkReceive
ID: 536870911  DLC: 255
---LOOP END---
checkReceive
ID: 536870911  DLC: 255

I tried D9 - D2 / D9 - D10

but its still same result.

Im plugging my shield on my r3 directly.

Metadata

Metadata

Assignees

Labels

Seeed_Arduino_CANLabel for Seeed_Arduino_CANUAYUnassigned yet

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions