jsj
June 9, 2022, 2:09pm
1
Hi.
I’m trying to use Timo’s great NMEA2000 library on a STM32.
How do I specify which SPI port to use?
I also have a TFT connected, which needs max SPI-speed, but the CAN controller has a max of 10MHz, so I want to use two SPI-ports on my STM32.
Im using a Bluepill, but changed the STM to a STM32F103CBT6 (more memory).
I’m using Visual Studio Code with PlatformIO - a ST-LINK for upload/debug, a MCP2515 as controller and MCP2542 for transceiver.
Libraries (Timo’s):
N2kMsg.h
NMEA2000.h
mcp_can.h
NMEA2000_mcp.h
N2kMessages.h
The micro should have 2xSPI, but I can’t find info how to use SPI2
Just tell me if you need more information…
I think library specific questions should go to Issues · ttlappalainen/NMEA2000 · GitHub .
I see that the library constructs this type of object which has a SetSPI
function
public:
tNMEA2000_mcp(unsigned char _N2k_CAN_CS_pin, unsigned char _N2k_CAN_clockset = MCP_16MHz,
unsigned char _N2k_CAN_int_pin = 0xff, uint16_t _rx_frame_buf_size=MCP_CAN_RX_BUFFER_SIZE);
void SetSPI(SPIClass *_pSPI) { N2kCAN.setSPI(_pSPI); }
at this place
#if !defined(USE_MCP_CAN_CLOCK_SET)
#define USE_MCP_CAN_CLOCK_SET 16
#endif
#if USE_MCP_CAN_CLOCK_SET == 8
#define MCP_CAN_CLOCK_SET MCP_8MHz
#else
#define MCP_CAN_CLOCK_SET MCP_16MHz
#endif
tNMEA2000 &NMEA2000=*(new tNMEA2000_mcp(N2k_SPI_CS_PIN,MCP_CAN_CLOCK_SET,N2k_CAN_INT_PIN,MCP_CAN_RX_BUFFER_SIZE));
#endif
#endif
So technically it might be possible to recast this pionter to its original type and call the SetSPI function on that…
#include <SPI.h>
// MOSI MISO SCLK
SPIClass SPI_3(PC12, PC11, PC10);
void setup() {
tNMEA2000_mcp* pNMEA = (tNMEA2000_mcp*) &NMEA2000;
pNMEA->SetSPI(&SPI_3);
}
Creating a new SPI object is per API · stm32duino/wiki Wiki · GitHub .
(untested).
jsj
June 9, 2022, 3:42pm
3
Thanks - I’ll try in the weekend…I’m very new to C++ so I might get back with questions