标题:数据类型转化的为问题
取消只看楼主
chen3bing
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:507
专家分:104
注 册:2008-11-12
结帖率:91.22%
已结贴  问题点数:10 回复次数:0 
数据类型转化的为问题
先贴上程序:

bool SERCOM6_SPI_WriteRead (void* pTransmitData, size_t txSize, void* pReceiveData, size_t rxSize)
{
    bool isRequestAccepted = false;
    uint32_t dummyData = 0U;

    /* Verify the request */
    if((((txSize > 0U) && (pTransmitData != NULL)) || ((rxSize > 0U) && (pReceiveData != NULL))) && (sercom6SPIObj.transferIsBusy == false))
    {
        if((SERCOM6_REGS->SPIM.SERCOM_CTRLB & SERCOM_SPIM_CTRLB_CHSIZE_Msk) == (uint32_t)SPI_DATA_BITS_9)
        {
            /* For 9-bit transmission, the txSize and rxSize must be an even number. */
            if(((txSize > 0U) && ((txSize & 0x01U) != 0U)) || ((rxSize > 0U) && ((rxSize & 0x01U) != 0U)))
            {
                return isRequestAccepted;
            }
        }

        isRequestAccepted = true;
        sercom6SPIObj.txBuffer = pTransmitData;
        sercom6SPIObj.rxBuffer = pReceiveData;
        sercom6SPIObj.rxCount = 0U;
        sercom6SPIObj.txCount = 0U;
        sercom6SPIObj.dummySize = 0U;

        if(pTransmitData != NULL)
        {
            sercom6SPIObj.txSize = txSize;
        }
        else
        {
            sercom6SPIObj.txSize = 0U;
        }

        if(pReceiveData != NULL)
        {
            sercom6SPIObj.rxSize = rxSize;
        }
        else
        {
            sercom6SPIObj.rxSize = 0U;
        }

        sercom6SPIObj.transferIsBusy = true;

        /* Flush out any unread data in SPI read buffer */
        while((SERCOM6_REGS->SPIM.SERCOM_INTFLAG & SERCOM_SPIM_INTFLAG_RXC_Msk) == SERCOM_SPIM_INTFLAG_RXC_Msk)
        {
            dummyData = SERCOM6_REGS->SPIM.SERCOM_DATA;
            (void)dummyData;
        }

        SERCOM6_REGS->SPIM.SERCOM_STATUS |= SERCOM_SPIM_STATUS_BUFOVF_Msk;

        SERCOM6_REGS->SPIM.SERCOM_INTFLAG |= (uint8_t)SERCOM_SPIM_INTFLAG_ERROR_Msk;

        if(sercom6SPIObj.rxSize > sercom6SPIObj.txSize)
        {
            sercom6SPIObj.dummySize = sercom6SPIObj.rxSize - sercom6SPIObj.txSize;
        }

        /* Start the first write here itself, rest will happen in ISR context */
        if((SERCOM6_REGS->SPIM.SERCOM_CTRLB & SERCOM_SPIM_CTRLB_CHSIZE_Msk) == (uint32_t)SPI_DATA_BITS_8)
        {
            if(sercom6SPIObj.txCount < sercom6SPIObj.txSize)
            {
                SERCOM6_REGS->SPIM.SERCOM_DATA = *((uint8_t*)sercom6SPIObj.txBuffer);

                sercom6SPIObj.txCount++;
            }
            else if(sercom6SPIObj.dummySize > 0U)
            {
                SERCOM6_REGS->SPIM.SERCOM_DATA = 0xFFU;

                sercom6SPIObj.dummySize--;
            }
            else
            {
                /* Do nothing */
            }
        }
        else
        {
            sercom6SPIObj.txSize >>= 1U;
            sercom6SPIObj.dummySize >>= 1U;
            sercom6SPIObj.rxSize >>= 1U;

            if(sercom6SPIObj.txCount < sercom6SPIObj.txSize)
            {
                SERCOM6_REGS->SPIM.SERCOM_DATA = *((uint16_t*)sercom6SPIObj.txBuffer) & SERCOM_SPIM_DATA_Msk;

                sercom6SPIObj.txCount++;
            }
            else if(sercom6SPIObj.dummySize > 0U)
            {
                SERCOM6_REGS->SPIM.SERCOM_DATA = 0xFFFFU & SERCOM_SPIM_DATA_Msk;

                sercom6SPIObj.dummySize--;
            }
            else
            {
                /* Do nothing */
            }
        }

        if(rxSize > 0U)
        {
            /* Enable ReceiveComplete  */
            SERCOM6_REGS->SPIM.SERCOM_INTENSET = (uint8_t)SERCOM_SPIM_INTENSET_RXC_Msk;
        }
        else
        {
            /* Enable the DataRegisterEmpty  */
            SERCOM6_REGS->SPIM.SERCOM_INTENSET = (uint8_t)SERCOM_SPIM_INTENSET_DRE_Msk;
        }
    }

    return isRequestAccepted;
}



bool SERCOM6_SPI_Write(void* pTransmitData, size_t txSize)
{
    return SERCOM6_SPI_WriteRead(pTransmitData, txSize, NULL, 0U);
}

bool SERCOM6_SPI_Read(void* pReceiveData, size_t rxSize)
{
    return SERCOM6_SPI_WriteRead(NULL, 0U, pReceiveData, rxSize);
}



void SPI1_Send_Byte(unsigned char dat)
{   
   
}

我想在SPI1_Send_Byte函数里调用SERCOM6_SPI_Write函数,可是SERCOM6_SPI_Write函数的参数是void*类型,那么

我这样写行不行呢?我感觉有点不对。

void* pTransmitData;
    pTransmitData=(void *)(dat);
    SERCOM6_SPI_Write(pTransmitData, 1);

高手指教,谢谢!
搜索更多相关主题的帖子: return the bool NULL void 
2023-02-01 14:17



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-511204-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.084019 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved