2021-06-03 07:03 AM
I work with SAM3X8E microcontroller (datasheet : https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-11057-32-bit-Cortex-M3-Microcontroller-SAM3X-SAM3A_Datasheet.pdf, page 676 to 707 for SPI)
I want to make a multi transfer bytes thanks to SPI Bus. I initialize my CS as a GPIO to control it manually. My CS, MOSI and CLK works well but my MISO always return me 0...
This is some screen of the signals :
CS :MOSI :
MISO :
This is my initialization of the SPI Bus :
/* Configure an SPI peripheral. */
spi_enable_clock(SPI0);
spi_disable(SPI0);
spi_reset(SPI0);
spi_set_master_mode(SPI0);
spi_disable_mode_fault_detect(SPI0);
spi_set_peripheral_chip_select_value(SPI0, SPI_CHIP_SEL);
/* data samples on rising edge because Polarity = Phase = 0 */
spi_set_clock_polarity(SPI0, SPI_CHIP_SEL, SPI_CLK_POLARITY);
spi_set_clock_phase(SPI0, SPI_CHIP_SEL, SPI_CLK_PHASE);
spi_set_bits_per_transfer(SPI0, SPI_CHIP_SEL, SPI_CSR_BITS_8_BIT);
spi_set_baudrate_div(SPI0, SPI_CHIP_SEL, (sysclk_get_peripheral_hz() / gs_ul_spi_clock));
SPI0->SPI_CSR[0] |= SPI_CSR_CSAAT;
spi_enable(SPI0);
This is the code of my multi tranfer bytes :
uint8_t ftData8;
EVE_cs_set(); //CS at 0
spi_transmit_32(...); //Make 4 spi_transmit(...)
ftData8 = spi_receive(0x00); /* read data byte by sending another dummy byte */
EVE_cs_clear(); //CS at 1
return ftData8; /* return byte read */
And this is the code of my function spi_transmit(...) :
static inline uint8_t spi_transmit(uint8_t data)
{
while ((SPI0->SPI_SR & SPI_SR_TDRE) == 0);
spi_write(SPI0, data, SPI_CHIP_SEL, 0);
while ((SPI0->SPI_SR & SPI_SR_RDRF) == 0);
uint8_t data_read, Chip_Sel_read;
spi_read(SPI0, &data_read, &Chip_Sel_read);
return data_read;
}
Can you see where is the problem ?
PS :
I have a screen of a workwell MISO (in the same case) if you want to see how it's should looks like :
2021-06-04 04:20 AM
No, I mean datasheet of the controller (the chip) on the display board.
Search further.
JW
2021-06-04 04:24 AM
I don't have it... I will ask at my tutor monday. I will keep you informed !
2021-06-04 04:36 AM
Ask google, it works on weekends, too.
JW
2021-06-04 05:39 AM
Check for SPI:
All of above have to be configured compatible between MCU and Device/Display.
As others said:
Paul
2021-06-04 06:14 AM
> Configure the SPI settings using STM32CubeMX
Hardly so, for ATSAM... :)
JW
2021-06-06 11:48 PM
2021-06-07 01:19 AM
2021-06-07 01:20 AM
I try to change my SPI settings, SPI PIN settings (MISO in input, ...) but nothing make my MISO works....
2021-06-07 02:27 AM
Hi, I have some news!
I thought the problem was with my SPI or PIN setup but after many changes it didn't do anything.
I reworked my functions and there I have a result (which does not work yet but encouraging).
Here is my MISO signal:
We can see that there is a response from the screen. However, the 8-bit multi transfers are maybe a little too stuck (no cut between 5 transfers) and my CS resets to 1 before the end of my multi transfer.
Here is my spi_trasnmit (data) function:
static inline void spi_transmit(uint8_t data)
{
while ((SPI0->SPI_SR & SPI_SR_TXEMPTY) == 1);
spi_write(SPI0, data, SPI_CHIP_SEL, 0);
while ((SPI0->SPI_SR & SPI_SR_TDRE) == 1);
}
Here is my spi_receive (data) function:
{
uint8_t data_read, Chip_Sel_read;
spi_transmit(data);
while((SPI0->SPI_SR & SPI_SR_RDRF) == 0);
spi_read(SPI0, &data_read, &Chip_Sel_read);
return data_read;
}
and here is the function I call to do my 5 byte transfer:
uint8_t ftData8;
EVE_cs_set(); //CS at 0
spi_transmit_32(...); //Make 4 spi_transmit(...)
ftData8 = spi_receive(0x00); /* read data byte by sending another dummy byte */
EVE_cs_clear(); //CS at 1
return ftData8; /* return byte read */
2021-06-07 04:01 AM
This is probably the point where you can't get any more help here, simply because this is STM32 forum, so users here typically don't use ATSAM. You might need to go to MCHP's ATSAM-related forum for specific help.
JW