大家好,我用arduino due在Atmel Studio 的ASF下实现SPI功能,没有成功,想问问是什么问题,运行后LED灯有闪,但是SPI的时钟和数据没有波形,麻烦帮忙看看问题在哪? 感谢
代码如下:
#include <asf.h>
#define LED IOPORT_CREATE_PIN(PIOB,27)
//#define MISO IOPORT_CREATE_PIN(PIOA,25)
//#define MOSI IOPORT_CREATE_PIN(PIOA,26)
//#define SPCK IOPORT_CREATE_PIN(PIOA,27)
//#define NPCS IOPORT_CREATE_PIN(PIOA,28)
#define DEFAULT_CHIP_ID 0
int main (void)
{
/* Insert system clock initialization code here (sysclk_init()). */
Spi SPI_EXAMPLE;
struct spi_device SPI_DEVICE_EXAMPLE1 = {.id = IOPORT_CREATE_PIN(PIOA,28)};
uint32_t SPI_EXAMPLE_BAUDRATE = 1000000;
uint8_t spi_data = 0x55;
uint32_t i=0;
board_init();
sysclk_init();
ioport_init();
uint8_t data_buffer[1] = {0xAA};
ioport_set_pin_mode(PIO_PA25_IDX,IOPORT_MODE_MUX_A);
ioport_disable_pin(PIO_PA25_IDX);
ioport_set_pin_mode(PIO_PA26_IDX,IOPORT_MODE_MUX_A);
ioport_disable_pin(PIO_PA26_IDX);
ioport_set_pin_mode(PIO_PA27_IDX,IOPORT_MODE_MUX_A);
ioport_disable_pin(PIO_PA27_IDX);
ioport_set_pin_mode(PIO_PA28_IDX,IOPORT_MODE_MUX_A);
ioport_disable_pin(PIO_PA28_IDX);
spi_master_init(&SPI_EXAMPLE);
spi_master_setup_device(&SPI_EXAMPLE,&SPI_DEVICE_EXAMPLE1,SPI_MODE_1,1000000,0);
spi_enable(&SPI_EXAMPLE);
// ioport_set_pin_dir(LED,IOPORT_DIR_OUTPUT);
while(1)
{
if( spi_is_tx_ready (&SPI_EXAMPLE) == 1)
{
spi_select_device(&SPI_EXAMPLE,&SPI_DEVICE_EXAMPLE1);
spi_write_packet(&SPI_EXAMPLE, data_buffer, 1);
spi_read_packet(&SPI_EXAMPLE, data_buffer, 1);
spi_deselect_device(&SPI_EXAMPLE,&SPI_DEVICE_EXAMPLE1);
ioport_toggle_pin_level(LED);
delay_ms(500);
}
else
{
ioport_set_pin_level(LED,IOPORT_PIN_LEVEL_HIGH);
}
}
/* Insert application code here, after the board has been initialized. */
}
此帖出自
小平头技术问答
一周热门 更多>