PN7462 HIF-SPI Tx is not work!

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

PN7462 HIF-SPI Tx is not work!

2,409 Views
wuyong_yi
Contributor I

Hi.

I'm using the PN7462AU. And want to communicate with another MICOM via HIF SPI slave mode.

Rx is working. When I sent from host - I mean another MICOM - to PN7462, received successfully. But try to receive from PN7462, I can't.

When I call the "phhalHif_Transmit()", first call returns "PH_ERR_SUCCESS". But can not receive any data. After the second call returns "PH_ERR_HIF_TX_BUFFER_LOCKED". I don't know why.

This is my code.

#define _4X_BUF_SIZE   64
uint32_t _4rx_buf_[_4X_BUF_SIZE];
void HIF_SPI_Init() {
    phhalHif_Config_t   hif_config = {
        .sConfig.sSpiConfig = _CPOL_LOW | _CPHA_ODD,
        .bTimeout       = 100,//0,
        .eInterface     = E_HIF_SPI,
        .eBufferType    = E_BUFFER_FORMAT_FREE,
        .bShortFrameLen = 0,
        .bStoreErrData  = 0,
        .bHeaderSize    = 0
    };
    PH_REG_CLEAR_BIT(PCR_PADOUT_REG, PADOUT_IRQ);
    phhalHif_Init(&hif_config, _hif_error_callback);
    phhalHif_InitRxBuffer(E_RX_BUFFER_ID0, _4X_BUF_SIZE * 4, _4rx_buf_, _hif_rx_callback);
}

static void _hif_tx_callback(uint32_t status, void *param) {
    tx_size_ = status;
}

int16_t HIF_TX_Timeout(uint8_t *stream, int16_t size, uint32_t timeout_ms) {
    tx_size_ = 0;
    memcpy((uint8_t*)_4tx_buf_, stream, size);
    if (phhalHif_Transmit(_4tx_buf_, size, _hif_tx_callback) == PH_ERR_SUCCESS) {
        // assert the IRQ line to sync with master
        PH_REG_SET_BIT(PCR_PADOUT_REG, PADOUT_IRQ);
        while ((tx_size_ == 0) && (timeout_ms-- > 0))
            phUser_Wait(1000);
       // de-assert the IRQ line to sync with master
        PH_REG_CLEAR_BIT(PCR_PADOUT_REG, PADOUT_IRQ);
        // first time return here
        return tx_size_;
    }
    // second, third, .. returns here
    return 0;
}

Again, when I call the "HIF_TX_Timeout()" function, it returns two types.

First call, returns tx_size_. And others return 0. And never Tx.

Help me.

Sorry for my poor english. I hope you can read this.

Tags (3)
0 Kudos
7 Replies

1,775 Views
sachin_singh
Contributor II

Hi @@amolboras & @wuyong_yi ,

I am also tried to developed the same spi communication using the HIF methods but it always receives zero in Rx buffer. I have tested it many different configuration but it is not working. After going through the above shared small codes I have seen uses of the "PCR_PADOUT_REG", does it required in communication of SPI using SPI on HIF port ?

And it will really great if I can get a proper configuration setting through which I can receive my data from master to slave's rx buffer.

Looking forward for the supports...

Warm Regards

Sachin

0 Kudos

1,939 Views
sachin_singh
Contributor II

Hi @amolborase  & @wuyong_yi ,

I am working on the same PN7462AU for the SPI communication and still facing the issues while communications.
As, I have gone through the phExHif & phExPos example for the taking the SPI example for the reference development. But even after the SPI communication is not working. I tried a lot with different many ways it is not even tx data properly and unable to receive the data in Rx_buff declared.
Even I am getting error after tx data "PH_ERR_HIF_TX_BUFFER_LOCKED".

I would request you to please let me know that how I do configure it and proceed for starting SPI communication.

Warm Regards
Sachin

 

0 Kudos

1,943 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Which mode are you setting for the SPI slave? HDLL? or native? Please refer to https://www.nxp.com/docs/en/user-guide/UM10858.pdf  for more details.


Have a great day,
Kan

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,943 Views
wuyong_yi
Contributor I

Thank you for your answer.

static void _hif_tx_callback(uint32_t status, void *param) {
    hif_.eot_ = true;
}
static void _hif_rx_callback(uint32_t status, void *param) {
    phhalHif_ReleaseRxBuffer(hif_.buf_id_);
    hif_.eor_ = true;
}
int16_t hif_tx_timeout(uint8_t *stream, int16_t size, uint32_t timeout_ms) {
    hif_.eot_ = false;
    hif_.tx_._1x_buf_[0] = (size >> 8) & 0xFF;
    hif_.tx_._1x_buf_[1] = (size >> 0) & 0xFF;
    hif_.tx_._1x_buf_[2] = 0;
    hif_.tx_._1x_buf_[3] = 0;
    memcpy(hif_.tx_._1x_buf_ + 4, stream, size);
    if (phhalHif_Transmit(hif_.tx_._4x_buf_, 4 + size, _hif_tx_callback) == PH_ERR_SUCCESS) {
        // assert the IRQ line to sync with master
        PH_REG_SET_BIT(PCR_PADOUT_REG, PADOUT_IRQ);
        while ((hif_.eot_ == false) && (timeout_ms-- > 0))
            phUser_Wait(1000);
        // de-assert the IRQ line to sync with master
        PH_REG_CLEAR_BIT(PCR_PADOUT_REG, PADOUT_IRQ);
        if (hif_.eot_)
            return size;
    }
    phhalHif_AbortTransmission();
    return 0;
}
int16_t hif_rx_timeout(uint8_t *stream, int16_t size, uint32_t timeout_ms) {
    while ((hif_.eor_ == false) && (timeout_ms-- > 0))
        phUser_Wait(1000);
    if (hif_.eor_) {
        hif_.eor_ = false;
        size = ((hif_.rx_._1x_buf_[0] << 8) & 0xFF00) | (hif_.rx_._1x_buf_[1] & 0xFF);
        memcpy(stream, (uint8_t*)hif_.rx_._1x_buf_ + 4, size);
        return size;
    }
    return 0;
}

This is whole my tx/rx code. Actually I really don't know how I should set up the SPI mode. I believe that I'm trying to slave-NATIVE mode. But not sure. How should I set the HDLL mode or Native mode?

This code works sometime. Only Tx or only Rx works. But Tx/Rx are mixed, something strange.

0 Kudos

1,943 Views
amolborase
Contributor II

Dear W. Y. YI,

Is your problem related to SPI Transmit get solved ? Because we are also facing same issue.

0 Kudos

1,943 Views
wuyong_yi
Contributor I

Yes, it worked now.

enum {

_CPOL_LOW = 0b00,
_CPOL_HIGH = 0b01,

_CPHA_EVEN = 0b00, // my guess
_CPHA_ODD = 0b10, // my guess

_BUFF_SIZE = 640 // free: max 256, native: max 1024
};

union _packet {

uint32_t _4x_buf_[_BUFF_SIZE / 4];
uint8_t _1x_buf_[_BUFF_SIZE];
};
typedef union _packet packet;
phhalHif_Config_t hif_config = {

.sConfig.sSpiConfig = _CPOL_HIGH | _CPHA_EVEN,
.bTimeout = 0,
.eInterface = E_HIF_SPI,
.eBufferType = E_BUFFER_FORMAT_NATIVE,
.bShortFrameLen = 0,
.bStoreErrData = 0,
.bHeaderSize = 0
};
phhalHif_Init(&hif_config, _hif_error_callback);
phhalHif_InitRxBuffer(E_RX_BUFFER_ID0, _BUFF_SIZE, rx_._4x_buf_, _hif_rx_callback);

In my case, it comes from buffer. Buffer size and type occurs problem. When I initiated the RxBuffer, I thought buffer size and pointer is byte. But not this. Size is byte, that's right. But pointer is x4's one. When I changed like this, everything works well.

0 Kudos

1,943 Views
amolborase
Contributor II

Hello W.Y.YI,

Thank you very much...

Our problem is solved and now SPI is working.

Sorry for Late reply  

Thanks & Regards,

Amol Borase

0 Kudos