我正试图从 XMC BSP 运行 HAL_SPI_Master 应用程序。 但我无法初始化我的 spi。函数" cyhal_spi_init" 返回结果值 = 67246343。
我通过设备配置器 4.20 在 SCB 3 上配置了 spi 设备(内存)。
我的 main.c:
#include "cyhal.h"#include "cybsp.h"#include "cy_retarget_io.h"/* SPI baud rate in Hz */#define SPI_FREQ_HZ (1000000UL)/* Delay of 1000ms between commands */#define CMD_TO_CMD_DELAY (1000UL)/* SPI transfer bits per frame */#define BITS_PER_FRAME (8)void handle_error(uint32_t status){ if (status != CY_RSLT_SUCCESS) { CY_ASSERT(0); }}int main(void){ cy_rslt_t result; uint8_t cmd_send = 0x9F; cyhal_spi_t mSPI; uint8_t rx_buffer[3] ={0xFF,0xFF,0xFF}; /* Ini
tialize the device and board peripherals */ result = cybsp_init(); /* Board init failed. Stop program execution */ handle_error(result); /* Initialize retarget-io for uart logs */ result = cy_retarget_io_init(CYBSP_DEBUG_UART_TX, CYBSP_DEBUG_UART_RX, CY_RETARGET_IO_BAUDRATE); /* Retarget-io init failed. Stop program execution */ handle_error(result); /* x1b[2Jx1b[;H - ANSI ESC sequence for clear screen */ printf("x1b[2Jx1b[;H"); printf("*************** " "HAL: SPI Master " "*************** rnn"); printf("Configuring SPI master...rn"); /* Init SPI master */ result = cyhal_spi_init( mSPI,CYBSP_SPI_MOSI,CYBSP_SPI_MISO,CYBSP_SPI_CLK, CYBSP_SPI_CS,NULL,BITS_PER_FRAME, CYHAL_SPI_MODE_00_MSB,false); handle_error(result); /* Set the SPI baud rate */ result = cyhal_spi_set_frequency( mSPI, SPI_FREQ_HZ); handle_error(result); /* Enable interrupts */ __enable_irq(); for (;;) { /* Send the command packet to the slave */ //result = cyhal_spi_send( mSPI, cmd_send); result = cyhal_spi_transfer( mSPI, cmd_send, sizeof(cmd_send), rx_buffer, sizeof(rx_buffer), 0xFF); handle_error(result); /* Give delay between commands */ cyhal_system_delay_ms(CMD_TO_CMD_DELAY); }}/* [] END OF FILE */