RT1061 LPSPI写TCR中的CONT和CPNTC位不生效

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RT1061 LPSPI写TCR中的CONT和CPNTC位不生效

Jump to solution
412 Views
TheSix
Contributor I

下面这张图是我在函数中设置CONT和CONTC位为0:

TheSix_0-1715588902039.png

TheSix_1-1715588961225.png

从串口输出界面可以看出,函数的设置并未生效。但是是我在另外的函数进行相同的设置却是可以生效的,这是为什么呢?如下图:

TheSix_2-1715589065452.png

TheSix_3-1715589139019.png

下面是我的未生效的函数代码的实现:

status_t FRAM_read(uint32_t address, uint32_t* buffer, uint32_t size)
{
    status_t status = kStatus_Success;
    uint32_t addr_low  = address & 0xff;
    uint32_t addr_high = address >> 8;

    uint32_t transfer_size    = size;
    uint32_t* transfer_buffer = buffer;

   /* Check that LPSPI is not busy. */
    if((LPSPI_GetStatusFlags(LPSPI1) & (uint32_t)kLPSPI_ModuleBusyFlag) != 0U)
    {
        return kStatus_LPSPI_Busy;
    }
   
    /* flush fifo. clear status flag. */
    LPSPI_FlushFifo(LPSPI1, true, true);
    LPSPI_ClearStatusFlags(LPSPI1, (uint32_t)kLPSPI_AllStatusFlag);
   
    PRINTF("1 SR:%x, TCR:%x\r\n", LPSPI1->SR, LPSPI1->TCR);
    /* start transfer.PCS is assered and RXMASK is de-assered. */
    LPSPI1->TCR |= LPSPI_TCR_CONT(true)|LPSPI_TCR_CONTC(true)|LPSPI_TCR_RXMSK(true);
    /*TCR is also shared the FIFO, so wait for TCR written.*/
    if (!LPSPI_WaitTxFifoEmpty(LPSPI1))
    {
        return kStatus_LPSPI_Timeout;
    }
   
    PRINTF("2 SR:%x, TCR:%x\r\n", LPSPI1->SR, LPSPI1->TCR);
    /* send read opcode and RXMASK is de-assered to start recieve data. */
    LPSPI_WriteData(LPSPI1, READ_OPCODE);
    LPSPI_WriteData(LPSPI1, addr_high);
    LPSPI_WriteData(LPSPI1, addr_low);
    LPSPI1->TCR &= (uint32_t)~LPSPI_TCR_RXMSK_MASK;
    if (!LPSPI_WaitTxFifoEmpty(LPSPI1))
    {
        return kStatus_LPSPI_Timeout;
    }
    PRINTF("3 SR:%x, TCR:%x\r\n", LPSPI1->SR, LPSPI1->TCR);
   
    while(transfer_size > 0)
    {
        LPSPI_WriteData(LPSPI1, (uint32_t)0);
        if((LPSPI_GetStatusFlags(LPSPI1) & (uint32_t)kLPSPI_RxDataReadyFlag) != 0U)
        {
           *transfer_buffer = LPSPI_ReadData(LPSPI1);
           //PRINTF("recieve data %d:%x\r\n", (size-transfer_size), *transfer_buffer);
           transfer_size--;
           transfer_buffer++;
        }
    }

    LPSPI1->TCR &= ~(LPSPI_TCR_CONTC_MASK | LPSPI_TCR_CONT_MASK);
    if (!LPSPI_WaitTxFifoEmpty(LPSPI1))
    {
        return kStatus_LPSPI_Timeout;
    }

    PRINTF("4 SR:%x, TCR:%x\r\n", LPSPI1->SR, LPSPI1->TCR);
   
    return status;
}

 

 

Labels (1)
0 Kudos
1 Solution
7 Replies
375 Views
davenadler
Senior Contributor I
0 Kudos
343 Views
TheSix
Contributor I
Thank you, this is very inspiring to me.
0 Kudos
330 Views
davenadler
Senior Contributor I

Glad to help, Don't forget to click "Kudos" on my posts!

It would be great if NXP would fix the FSL drivers - this is apparently a known problem (but not documented in errata nor fixed in FSL).

Best Regards, Dave

0 Kudos
400 Views
Gavin_Jia
NXP TechSupport
NXP TechSupport

Hi @TheSix ,

从这个输出来看确实很奇怪。可以尝试加一个打印在if语句之前吗?应该置位是成功的,如果这样是不是说明在等待TxFifo发送的时候又被其他函数改变了?

Best regards,
Gavin

0 Kudos
395 Views
TheSix
Contributor I
在if之前打印TCR的值也是同样的结果,写TCR寄存器的值并未生效。而且在代码中并没有在其他的地方再修改这个TCR的值。这个问题太奇怪了。
0 Kudos
387 Views
Gavin_Jia
NXP TechSupport
NXP TechSupport

尝试一下先禁用中断再修改寄存器呢?等处理逻辑结束之后再使能中断。

0 Kudos
349 Views
TheSix
Contributor I
我的程序中并没有开启任何中断,并且仅仅只使用了LPSPI这一个外设。尽管如此,我还是去尝试禁用了中断,但是仍然结果仍然是一样的。
0 Kudos