英飞凌
直播中

陈存楼

7年用户 1123经验值
私信 关注

从XMC BSP运行 HAL_SPI_Master应用程序,为什么无法初始化spi?

我正试图从 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};    /* Initialize 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 */

                                                                                                                                                                                                                                                                                                                                                                                                        
                                                      

回帖(1)

叹久

2024-5-30 16:24:07
首先,我们需要了解错误代码67246343。在Cypress HAL中,错误代码是一个32位的值,其中每个位表示不同的错误。要理解这个错误代码,我们需要将其与Cypress文档中的错误代码进行比较。

错误代码67246343的二进制表示为:1000111101100011。
根据Cypress文档,我们可以找到以下错误位:

- 位31(0x80000000):无错误
- 位30(0x40000000):无错误
- 位29(0x20000000):无错误
- 位28(0x10000000):无错误
- 位27(0x08000000):无错误
- 位26(0x04000000):无错误
- 位25(0x02000000):无错误
- 位24(0x01000000):无错误
- 位23(0x00800000):无错误
- 位22(0x00400000):无错误
- 位21(0x00200000):无错误
- 位20(0x00100000):无错误
- 位19(0x00080000):无错误
- 位18(0x00040000):无错误
- 位17(0x00020000):无错误
- 位16(0x00010000):无错误
- 位15(0x00008000):无错误
- 位14(0x00004000):无错误
- 位13(0x00002000):无错误
- 位12(0x00001000):无错误
- 位11(0x00000800):无错误
- 位10(0x00000400):无错误
- 位9(0x00000200):无错误
- 位8(0x00000100):无错误
- 位7(0x00000080):无错误
- 位6(0x00000040):无错误
- 位5(0x00000020):无错误
- 位4(0x00000010):无错误
- 位3(0x00000008):无错误
- 位2(0x00000004):无错误
- 位1(0x00000002):无错误
- 位0(0x00000001):无错误

由于所有位都为0,这意味着没有错误。但是,这与我们观察到的行为不符。这可能是因为错误代码没有正确地从函数中返回,或者错误代码的定义在文档中没有列出。

为了解决这个问题,我们可以按照以下步骤进行:

1. 确保您的硬件连接正确,包括SPI数据线、时钟线和片选线。

2. 检查您的设备配置器设置,确保SPI配置正确。

3. 在初始化SPI之前,确保调用`cyhal_system_init()`和`cybsp_init()`。

4. 检查您的SPI初始化代码,确保所有参数都设置正确。


举报

更多回帖

发帖
×
20
完善资料,
赚取积分