您的位置: OpenADSP社区论坛 -> Blackfin专区 -> 新手上路 -> [求助]关于BF609通过SPORT口读取AD7357的采... 
本帖共有328个阅读者
发表帖子 发表投票 回复主题
[求助]关于BF609通过SPORT口读取AD7357的采样数据出错问题
wqs(论坛新手)
wqs
头衔:社区公民
帮派:无帮无派
帖数:20
金钱:310
积分:34
注册时间:2011/12/15
楼主信息 | 留言 | Email | 主页 | 编辑 | 管理 | 离线
[求助]关于BF609通过SPORT口读取AD7357的采样数据出错问题
哪位大神有做过用BF609通过SPORT口读取AD7357的采样数据的相关应用的,能否共享下SPORT的配置及数据读取的相关程序,我自己写的一直读取错误。多谢!!

/* size of the sport RX buffer */
#define SIZE_OF_RX_BUFFER      8U

static UInt32 channel0_data[2];     // Save the AD data from SPORT1_A
static UInt32 channel1_data[2];     // Save the AD data from SPORT1_B
/* Memory required by the device for RX operation */
UInt8 sport_handlerRx0[SPORT_MEM_SIZE]; // SPORT1_A
UInt8 sport_handlerRx1[SPORT_MEM_SIZE]; // SPORT1_B
/* Rx  Buffer for ADC0/SPORT1_A */
UInt8 nBufferRx0[SIZE_OF_RX_BUFFER];
/* Rx  Buffer for ADC1/SPORT1_B */
UInt8 nBufferRx1[SIZE_OF_RX_BUFFER];

void SPORT_START(void)
{
    ADI_SPORT_RESULT eResult;
    eResult = adi_sport_SubmitBuffer(hDeviceRx0, nBufferRx0, SIZE_OF_RX_BUFFER);
    eResult |= adi_sport_SubmitBuffer(hDeviceRx1, nBufferRx1, SIZE_OF_RX_BUFFER);
    if (eResult == ADI_SPORT_SUCCESS)
    {
        eResult = adi_sport_Enable(hDeviceRx0, true);
        eResult |= adi_sport_Enable(hDeviceRx1, true);
        /* Enable the Data flow for Rx */
        if (eResult != ADI_SPORT_SUCCESS)
        {
            //printf("COREB:Failed to enable the Rx\n");
            total_state1 = 0x0200;
        }
    }
    else
    {
        //printf("COREB:\n\t Failed to submit the buffer1 for Rx channel:  %d",eResult);
        total_state1 = 0x0100;
    }
}

static void SPORTCallbackRx0(void *pAppHandle, UInt32 nEvent, void *pArg)
{
    ADI_SPORT_RESULT eResult;
    ADI_SPORT_EVENT event = (ADI_SPORT_EVENT)nEvent;
    switch (event)
    {
        case ADI_SPORT_EVENT_RX_BUFFER_PROCESSED:
            eResult = adi_sport_Enable(hDeviceRx0, false);
            ++nRxCallbackCounter;
            gb_sport1a_callback = true;
            break;
        default:
            break;
    }
}
static void SPORTCallbackRx1(void *pAppHandle, UInt32 nEvent, void *pArg)
{
    ADI_SPORT_RESULT eResult;
    ADI_SPORT_EVENT event = (ADI_SPORT_EVENT)nEvent;
    switch (event)
    {
        case ADI_SPORT_EVENT_RX_BUFFER_PROCESSED:
            eResult = adi_sport_Enable(hDeviceRx1, false);
            ++nRxCallbackCounter;
            gb_sport1b_callback = true;
            break;
        default:
            break;
    }
}

static void SPORT_INIT(void)
{
    ADI_SPORT_RESULT eResult;
    eResult = adi_sport_Open(SPORT_DEVICE_NUM, ADI_HALF_SPORT_A, ADI_SPORT_DIR_RX,
        ADI_SPORT_SERIAL_MODE, sport_handlerRx0, (UInt32) (SPORT_MEM_SIZE), &hDeviceRx0);
    eResult |= adi_sport_Open(SPORT_DEVICE_NUM, ADI_HALF_SPORT_B, ADI_SPORT_DIR_RX,
        ADI_SPORT_SERIAL_MODE, sport_handlerRx1, (UInt32) (SPORT_MEM_SIZE), &hDeviceRx1);
    if (eResult != ADI_SPORT_SUCCESS)
    {
        //printf("COREB:\n\tFailed to open sport#1 in Rx mode ");
        total_state1 |= 0x0001;
        return;
    }
    /* configure the sport for data length 16bit, MSB first etc */
    eResult = adi_sport_ConfigData(hDeviceRx0, ADI_SPORT_DTYPE_ZERO_FILL, 15U, false, false, false);
    eResult |= adi_sport_ConfigData(hDeviceRx1, ADI_SPORT_DTYPE_ZERO_FILL, 15U, false, false, false);
    if (eResult != ADI_SPORT_SUCCESS)
    {
        //printf("COREB:adi_sport1_ConfigData Error!\n");
        total_state1 |= 0x0002;
        return;
    }
    /* configure the clock for the SPORT. This API set the whether use the internal clock, SPORT clock etc.
    * Since this example, RX  gets the clock and Frame sync from TX. */
    // internal clock, clock ratio  sysclk/16, posedge,  gated clock.
    // Clock divider set divided by 32, to receive the correct rate
    eResult = adi_sport_ConfigClock(hDeviceRx0, 31, true, true, true);
    eResult |= adi_sport_ConfigClock(hDeviceRx1, 31, true, true, true);
    if (eResult != ADI_SPORT_SUCCESS)
    {
        //printf("COREB:adi_sport1_ConfigClock Error!\n");
        total_state1 |= 0x0004;
        return;
    }
    /* Configure the frame sync. This API configure the SPORT whether to use frame sync or not , external or internal framesync etc */
    // edge, late, active low, data independent
    eResult = adi_sport_ConfigFrameSync(hDeviceRx0, 31, true, true, true, true, true, false);
    eResult |= adi_sport_ConfigFrameSync(hDeviceRx1, 31, true, true, true, true, true, false);
    if (eResult != ADI_SPORT_SUCCESS)
    {
        //printf("COREB:adi_sport1_ConfigFrameSync Error!\n");
        total_state1 |= 0x0008;
        return;
    }
    // DMA mode is enabled by default,there will be a problem more than doubled the number of frame synchronization
    //#define  ENABLE_DMA_MODE  // test co-work with emac1 20121108
#ifdef  ENABLE_DMA_MODE
    /* Enable the DMA associated with device if it is expected to work with DMA mode */
    // Switch interrupt
    if((eResult = adi_sport_EnableDMAMode(hDeviceRx0,true))!= ADI_SPORT_SUCCESS)
    {
        ; //printf("COREB:\n\t Failed to enable the DMA mode for RX0:   %d",eResult);
    }
    if((eResult = adi_sport_EnableDMAMode(hDeviceRx1,true))!= ADI_SPORT_SUCCESS)
    {
        ; //printf("COREB:\n\t Failed to enable the DMA mode for RX1:   %d",eResult);
    }
#endif
    /* Register a call back function for RX channel. Registered callback function will be called as and when
    * an filled buffer is avilable.
    */
    eResult = adi_sport_RegisterCallback(hDeviceRx0, SPORTCallbackRx0, hDeviceRx0);
    eResult |= adi_sport_RegisterCallback(hDeviceRx1, SPORTCallbackRx1, hDeviceRx1);
    if (eResult != ADI_SPORT_SUCCESS)
    {
        //printf("COREB:\n\t Failed to register the call back for Rx1 :  %d",eResult);
        total_state1 |= 0x0010;
        return;
    }
}

void main()
{
    ....
    SPORT_INIT();
    .....
    //CS引脚下降沿中断中调用SPORT_INIT();
        ....

    while (1)
    {
        ....
        if (gb_sport1a_callback && gb_sport1b_callback)
        {
            // AD Sampling Ready
            gb_sport1a_callback = false; // After execution cleared
            gb_sport1b_callback = false; // After execution cleared

            memcpy((unsigned char *) channel0_data, (unsigned char *) nBufferRx0, SIZE_OF_RX_BUFFER); // SPORT1_A
            memcpy((unsigned char *) channel1_data, (unsigned char *) nBufferRx1, SIZE_OF_RX_BUFFER); // SPORT1_B
       }
}

这家伙很懒,什么也没有留下!
等级:论坛新手 参考IP地址:*.*.*.*
2017/11/3 18:28:24
尊贵身份标志
OpenADSP(管理员)
OpenADSP
头衔:社区公民
帮派:无帮无派
帖数:5187
金钱:34761
积分:6369
注册时间:2011/6/7
1信息 | 留言 | Email | 主页 | 编辑 | 管理 | 离线
没搞过这个,不是很清楚了。

我是OP...
等级:管理员 参考IP地址:*.*.*.*
2017/11/7 9:10:27
Powered by OpenADSP Copyright © 2010 www.Openadsp.com. All rights reserved.154481 Call, 1 Queries, Processed in 0.015625 second(s),