dedalqq / esp32-mcp2515

MCP2515 CAN interface library for using on esp32/esp8266
MIT License
51 stars 16 forks source link

Board reboots after connecting two spi lines. #7

Open GiovanniRaseraF opened 1 year ago

GiovanniRaseraF commented 1 year ago
          On the circuit I made, the mcp and gps module communicate over the same spi line, but the cs pins are separate. After pulling data over MCP, when I do digitalWrite("mcp' cs pin", HIGH), it goes into SPI_FLASH_BOOT mode and boots continuously.

At the same time, when I run the code without making any connections, the DATA part is empty and the ID part is written. Is it normal? I'll be glad, if you help me

Originally posted by @MehmetAliAksoy1 in https://github.com/dedalqq/esp32-mcp2515/issues/4#issuecomment-1454732263

GiovanniRaseraF commented 1 year ago

hi @MehmetAliAksoy1 please post the code you think is important here, so we can try to help you :)

MehmetAliAksoy1 commented 1 year ago
Ekran Resmi 2023-03-05 01 11 01

i only added two lines to your example code. The reason I added was to make mcp's cs pin HIGH and cut off communication, gps' cs pin to LOW and open it to communication. When i add this like that, on serial monitor SPI_FLASH_BOOT_MODE writing repeatedly

MehmetAliAksoy1 commented 1 year ago

Actually i want to select cs pin and take data from gps and spi

MehmetAliAksoy1 commented 1 year ago

how can i add gps's spi pin to same spi channel? please help @GiovanniRaseraF

GiovanniRaseraF commented 1 year ago

Check some things:

MehmetAliAksoy1 commented 1 year ago

Pins are correct, but i want to select CS pin when i use

GiovanniRaseraF commented 1 year ago

Okay, please try all the things and report your findings. And please provide the name of the gps that you are using.

MehmetAliAksoy1 commented 1 year ago

include

define GPS_CS 26

void spi_read(char* data) { digitalWrite(GPS_CS, LOW); delay(10); for (int i = 0; i < 100; i++) { data[i] = SPI.transfer(0x00); } digitalWrite(GPS_CS, HIGH); }

void setup() { Serial.begin(9600); SPI.begin(14, 12, 13, 26); //sck, miso, mosi, ss pinMode(GPS_CS, OUTPUT); digitalWrite(GPS_CS, HIGH); }

void loop() { char gps_data[100]; spi_read(gps_data); Serial.println(gps_data); delay(1000); }

This gps code working and print datas. Gps module is Neo-m8.

When I combine this code with the CAN code, I cannot receive data from GPS. Even when I turn the MCP's CS pin high, data starts coming directly from the can.

MehmetAliAksoy1 commented 1 year ago

When i call SPI.begin() after The canbus integration at Setup, it is working, why? @GiovanniRaseraF

GiovanniRaseraF commented 1 year ago

I think the problem is that you are using SPI in the wrong way, i cannot test it so i cannot be sure. And i think that Neo-m8 uses I2C at 9600 baud.

The best thing i can tell you is to:

And at the end post the code in you git and link it here or post it here with a markdown tag; it will be easier to read

MehmetAliAksoy1 commented 1 year ago

No, we made connection with both of them on HSPI. But gps's select pin 26. I can not use i2c

MehmetAliAksoy1 commented 1 year ago

And also your code does not work for me now

MehmetAliAksoy1 commented 1 year ago

I solved the problem but i did not any connection to mcp2515 from read the data. But on the serial monitor: ID: 447 DATA: ID: 42C DATA: ID: 50A DATA: ID: 12E DATA: ID: 341. What is this data came from? How is it possible? @GiovanniRaseraF

MehmetAliAksoy1 commented 1 year ago

There is no change when SS pin select another free pin.

Cyberko102 commented 10 months ago

I solved the problem but i did not any connection to mcp2515 from read the data. But on the serial monitor: ID: 447 DATA: ID: 42C DATA: ID: 50A DATA: ID: 12E DATA: ID: 341. What is this data came from? How is it possible? @GiovanniRaseraF

Could you show me your code for can bus?