Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting trash from SPI on SAMD21G18A (arduino-nano-33-iot) #16247

Closed
IchiroKuroki opened this issue Mar 29, 2021 · 5 comments
Closed

Getting trash from SPI on SAMD21G18A (arduino-nano-33-iot) #16247

IchiroKuroki opened this issue Mar 29, 2021 · 5 comments

Comments

@IchiroKuroki
Copy link
Contributor

Description

When I run the test for sending data through the SPI (tests / periph_spi), garbage is written to the output buffer. If I use -1 for the cs port parameter in this test, then the board hangs. A similar effect is observed if I call spi_init_cs (0, SPI_HWCS (0)); Board - arduino-nano-33-iot(SAMD21G18A)

Steps to reproduce the issue

cd tests/periph_spi
make flash BOARD=arduino-nano-33-iot
make term BOARD=arduino-nano-33-iot

call command init:
init 0 0 0 0 14
call command send:
send TEST_DATA

Expected results

021-03-29 17:05:02,075 # .04-devel-1152-g28e6)
2021-03-29 17:05:02,076 # Manual SPI peripheral driver test (see README.md)
2021-03-29 17:05:02,077 # There are 1 SPI devices configured for your platform.
init 0 0 0 0 14
2021-03-29 17:05:22,318 # init 0 0 0 0 14
2021-03-29 17:05:22,320 # SPI_DEV(0) initialized: mode: 0, clk: 0, cs_port: 0, cs_pin: 14
send TEST_DATA
2021-03-29 17:05:37,597 # send TEST_DATA
2021-03-29 17:05:37,598 # Sent bytes
2021-03-29 17:05:37,599 # 0 1 2 3 4 5 6 7 8
2021-03-29 17:05:37,600 # 0x54 0x45 0x53 0x54 0x5f 0x44 0x41 0x54 0x41
2021-03-29 17:05:37,601 # T E S T _ D A T A
2021-03-29 17:05:37,601 #
2021-03-29 17:05:37,601 # Received bytes
2021-03-29 17:05:37,602 # 0 1 2 3 4 5 6 7 8
2021-03-29 17:05:37,603 # 0x54 0x45 0x53 0x54 0x5f 0x44 0x41 0x54 0x41
2021-03-29 17:05:37,604 # T E S T _ D A T A

Actual results

2021-03-29 17:05:02,075 # .04-devel-1152-g28e6)
2021-03-29 17:05:02,076 # Manual SPI peripheral driver test (see README.md)
2021-03-29 17:05:02,077 # There are 1 SPI devices configured for your platform.
init 0 0 0 0 14
2021-03-29 17:05:22,318 # init 0 0 0 0 14
2021-03-29 17:05:22,320 # SPI_DEV(0) initialized: mode: 0, clk: 0, cs_port: 0, cs_pin: 14
send TEST_DATA
2021-03-29 17:05:37,597 # send TEST_DATA
2021-03-29 17:05:37,598 # Sent bytes
2021-03-29 17:05:37,599 # 0 1 2 3 4 5 6 7 8
2021-03-29 17:05:37,600 # 0x54 0x45 0x53 0x54 0x5f 0x44 0x41 0x54 0x41
2021-03-29 17:05:37,601 # T E S T _ D A T A
2021-03-29 17:05:37,601 #
2021-03-29 17:05:37,601 # Received bytes
2021-03-29 17:05:37,602 # 0 1 2 3 4 5 6 7 8
2021-03-29 17:05:37,603 # 0xb0 0x07 0xcd 0xd4 0xa4 0x76 0x27 0x34 0x4c
2021-03-29 17:05:37,604 # ?? ?? ?? ?? ?? v ' 4 L

Versions

2021.01 and .04-devel-1152-g28e6

@IchiroKuroki IchiroKuroki changed the title Get trash from SPI on SAMD21G18A (arduino-nano-33-iot) Getting trash from SPI on SAMD21G18A (arduino-nano-33-iot) Mar 29, 2021
@dylad
Copy link
Member

dylad commented Mar 31, 2021

@IchiroKuroki
I started to look at your issue to see if there is something wrong, did you manage to fix it on your side in the mean time ?

@IchiroKuroki
Copy link
Contributor Author

IchiroKuroki commented Mar 31, 2021

@dylad
I think I was not using this test correctly. And the expected result is not correct. I'm new to programming microcontrollers, and I didn't want to waste your time, so I closed the issue until I was sure that this was a real problem.

@dylad
Copy link
Member

dylad commented Mar 31, 2021

@IchiroKuroki thanks for your reply.
Feels free to reopen this if you have questions. (I'll still check on my side at some point later).

@dylad
Copy link
Member

dylad commented Mar 31, 2021

FYI,
I've tested tests/periph_spi on a arduino-zero clone, and issue the very same commands. It works as expected.
I suggest you to check your connection between MISO and MOSI, if MISO and MOSI are connected together, you should check your periph_conf.h to see if it match your hardware.

@IchiroKuroki
Copy link
Contributor Author

@dylad
I checked boards/arduino-nano-33-iot/include/periph_conf.h and saw that there is a configuration defined only for SPI used to communicate with U-blox NINA-W102, soldered on the board:
static const spi_conf_t spi_config[] = {
{ /* Connected to NINA W102 */
.dev = &SERCOM4->SPI,
.miso_pin = GPIO_PIN(PA, 13),
.mosi_pin = GPIO_PIN(PA, 12),
.clk_pin = GPIO_PIN(PA, 15),
.miso_mux = GPIO_MUX_D,
.mosi_mux = GPIO_MUX_D,
.clk_mux = GPIO_MUX_D,
.miso_pad = SPI_PAD_MISO_1,
.mosi_pad = SPI_PAD_MOSI_0_SCK_3,
.gclk_src = SAM0_GCLK_MAIN,
},
};

But MISO/MOSI on pins PA16 and PA19 are also available on the board. I extended the configuration as follows:
static const spi_conf_t spi_config[] = {
{
.dev = &SERCOM3->SPI,
.miso_pin = GPIO_PIN(PA, 19),
.mosi_pin = GPIO_PIN(PA, 16),
.clk_pin = GPIO_PIN(PA, 17),
.miso_mux = GPIO_MUX_D,
.mosi_mux = GPIO_MUX_D,
.clk_mux = GPIO_MUX_D,
.miso_pad = SPI_PAD_MISO_3,
.mosi_pad = SPI_PAD_MOSI_0_SCK_1,
.gclk_src = SAM0_GCLK_MAIN,
},
{ /* Connected to NINA W102 */
.dev = &SERCOM4->SPI,
.miso_pin = GPIO_PIN(PA, 13),
.mosi_pin = GPIO_PIN(PA, 12),
.clk_pin = GPIO_PIN(PA, 15),
.miso_mux = GPIO_MUX_D,
.mosi_mux = GPIO_MUX_D,
.clk_mux = GPIO_MUX_D,
.miso_pad = SPI_PAD_MISO_1,
.mosi_pad = SPI_PAD_MOSI_0_SCK_3,
.gclk_src = SAM0_GCLK_MAIN,
},
};

And after that the test gave the expected result with init 0 0 0 0 21.
Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants