• AVR Freaks

Hot!PIC24FJ128GA310(SPI master) read M90E32AS(SPI slave) register, always reads 0xFFFF

Author
frankie157
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2020/02/20 21:08:16
  • Location: 0
  • Status: offline
2020/02/23 19:00:09 (permalink)
0

PIC24FJ128GA310(SPI master) read M90E32AS(SPI slave) register, always reads 0xFFFF

Hi, all
I use PIC24FJ128GA310(SPI master) through SPI mode to read M90E32AS(SPI slave) register, but always reads 0xFFFF. 
I use the spi library generated by MPLAB MCC and set PIC24FJ128GA310(SPI master) to SPI MODE 2.
According to M90E32AS datasheet, I should set spi master to spi mode 2 and comunication width 16 bit.
 

int main(void)
{
    uint16_t val = 0;
    SPI1_STATUS status = 0;

    SYSTEM_Initialize();

    // Set power mode of M90E32AS to Normal mode
    PM0_SetHigh();
    PM1_SetHigh();
    
    // delay two seconds
    __delay_ms(2000);

    
    uint16_t address = 0x0031;
    
    while (1)
    {
        SS1OUT_SetLow();
        INTERRUPT_GlobalDisable();

        // Send read command
        SPI1_Exchange16bit(address | 0x8000);
        // Read the result
        val = SPI1_Exchange16bit(0x0000);
        
        SS1OUT_SetHigh();
        INTERRUPT_GlobalEnable();

        __delay_ms(10);
    }
}

 
Are there any problems?
Thanks.
 
 

Attached Image(s)

#1
Aussie Susan
Super Member
  • Total Posts : 3756
  • Reward points : 0
  • Joined: 2008/08/18 22:20:40
  • Location: Melbourne, Australia
  • Status: offline
Re: PIC24FJ128GA310(SPI master) read M90E32AS(SPI slave) register, always reads 0xFFFF 2020/02/25 18:33:58 (permalink)
0
I don't know MCC code (the SPI module is so simple to use that I don't like the MCC overhead and hidden 'features') but the SPI module performs exchanges - I suspect that you need to read what the first call to SPI1_Exchange16Bit() is returning.
Calling the funtion a 2nd time will be performing a 2nd exchange and it really depends on the slave wheat it wil send back in that situation.
Susan
#2
Jump to:
© 2020 APG vNext Commercial Version 4.5