kendryte / kendryte-standalone-sdk

Standalone SDK for kendryte K210
https://kendryte.com
Apache License 2.0
445 stars 162 forks source link

SPI endian #37

Closed michprev closed 5 years ago

michprev commented 5 years ago

BUG REPORT

I am not sure what exactly means data_bit_length in spi_init but SPI does not seem to work when setting endian to 1. I would expect it to swap order of sent bytes or bits but SPI sends all zeroes instead.

endian set to 1 image

endian set to 0 image

Test code

#include <stdio.h>
#include "gpio.h"
#include "bsp.h"
#include "sysctl.h"
#include "fpioa.h"
#include "spi.h"

int main()
{
    gpio_init();
    dmac_init();

    sysctl_set_power_mode(SYSCTL_POWER_BANK0, SYSCTL_POWER_V33);
    sysctl_set_power_mode(SYSCTL_POWER_BANK1, SYSCTL_POWER_V33);
    sysctl_set_power_mode(SYSCTL_POWER_BANK2, SYSCTL_POWER_V33);
    sysctl_set_power_mode(SYSCTL_POWER_BANK3, SYSCTL_POWER_V33);
    sysctl_set_power_mode(SYSCTL_POWER_BANK4, SYSCTL_POWER_V33);
    sysctl_set_power_mode(SYSCTL_POWER_BANK5, SYSCTL_POWER_V33);
    sysctl_set_power_mode(SYSCTL_POWER_BANK6, SYSCTL_POWER_V18);
    sysctl_set_power_mode(SYSCTL_POWER_BANK7, SYSCTL_POWER_V18);

    fpioa_set_function(9, FUNC_SPI1_SCLK);
    fpioa_set_function(10, FUNC_SPI1_D0);
    fpioa_set_function(11, FUNC_SPI1_SS0);

    spi_init(SPI_DEVICE_1, SPI_WORK_MODE_0, SPI_FF_STANDARD, 8, 1);
    spi_set_clk_rate(SPI_DEVICE_1, 1000000);

    uint8_t cmd = 0xA5;
    uint8_t data[] = { 0x01, 0x20, 0x03, 0x40 };

    while(1)
    {
        spi_send_data_standard(SPI_DEVICE_1, SPI_CHIP_SELECT_0, &cmd, 0, data, 4);
        sleep(1);
    }
}

Document version

248fbcd

Hardware

Sipeed Dan Dock

zzxcanaan commented 5 years ago

"endian" is used for dma when "data_bit_length" is greater than 8.