admin管理员组

文章数量:1290759

#include <stdint.h>
#include <stdbool.h>
#include <reg_mg82f6d64.h>

#define RegFifo       0x00
#define RegIrqFlags1     0x27
#define RegIrqFlags2     0x28

void wrb(uint8_t dat);
void read_single(uint8_t reg);
void w_f_rc(void);
void rlc1(void);
void w_f_fs(void);

uint8_t masterInput;

void main()
{
    INITs();
     w_f_fs();// 0x04 ->0x90
     //;---set receiver mode
     w_f_rc();// 0x08 ->0xD8
 while (1) {
    read_single(RegIrqFlags2);
    if ((masterInput == 0x40)) //check if there is any byte in FIFO
    {
            read_single(RegFifo);// I should read 0x04 means the message 4 byte long
            read_single(RegFifo);// Then I should read rest of the message with following lines below
            read_single(RegFifo);//But I still gets from SPI 0x04
            read_single(RegFifo);// and here 0x04
            read_single(RegFifo);// and here 0x04
            read_single(RegFifo);// and here 0x04
    }
  }
}



//***************************************************************
//; this function only reads 1Byte from SX1231
void read_single(uint8_t reg)
{
    EA  = 0;
    P14 = 0; // nSS -> LOW  (SPI ON)
    EA  = 1;

    wrb((reg & 0x7F));
    wrb(reg);

    EA  = 0;
        P14 = 1; // nSS -> HIGH  (SPI OFF)
    EA  = 1;
}

//;********************************************************************************************
//; this function write to MOSI from the "dat" paramater,
//  also write to masterInput variable from the MISO
void wrb(uint8_t dat) // (write read byte)
{
    while ((SPSTAT & 0x80) != 0); // wrb0: //(A != 0);
    SPDAT = dat;
    while ((SPSTAT & 0x80) == 0); // herebe: //(A == 0);
    masterInput = SPDAT;
}






void w_f_fs(void)
{
    wrt_single(RegOpMode, 0x08);//0x04 // ;frequency synthesiser mode

    read_single(RegIrqFlags1);//0x90
    while ((masterInput & 0x10) == 0) //;pll locked?
    {                       // sinR:
        read_single(RegIrqFlags1);
    }
}

void rlc1(void)
{
    read_single(RegIrqFlags1);//0xD8
    while ((masterInput & 0x80) == 0) // rlc1:
    {
        read_single(RegIrqFlags1);
    }
}

//--------------------------------------
// wait for sx1231's change mode to receive
void w_f_rc(void)
{
    wrt_single(RegOpMode, 0x10);//0x08 //;receive mode
    rlc1();
}

I can only read from the MISO is "0x04" which means the received data is 4 byte long, but there is no access to the messages. There is a tablet with same SX1231 an there is an ON/OFF controller device, both of them should comminnicate and they are doing it already but when i see there is a data came ı just able to read first byte(0x04) which mean the recieved data is 4Byte long and then I can not read the rest of the 4Byte data.

My CPU 8051 arch from megawin MG82F6D64 it is connected with SX1231 RF Integrated via SPI;
P1.4 = Slave Select

P1.5 = MOSI

P1.6 = MISO

P1.7 = SCK

Here is the original assembly code which is working well;

Received_RF:        DS 5
NODE:           DS 4
PRELST:         DS 2


; incoming message writes to Received_RF buffer
;if overflow occurs or length is not 4, exits with no

; Format of RF message from tablet:
;   4
;   id1
;   id2
;   device
;   operation
rf_rec_to_main:
        MOV   B,#RegFifo    ;message length
        LCALL read_single
        MOV   Received_RF,A
        CJNE  A,#4,rrtm0

        MOV   B,#RegFifo    ;id1
        LCALL read_single
        MOV   NODE,A
        
        MOV   B,#RegFifo    ;id2
        LCALL read_single
        MOV   NODE+1,A
        
        MOV   B,#RegFifo    ;device id
        LCALL read_single
        MOV   NODE+2,A
        
        MOV   B,#RegFifo    ;useful info (80,81)
        LCALL read_single
        MOV   NODE+3,A
        CJNE  A,#20h,same1
        JMP   rrtm5         ;promotion?


read_single:    ANL   IE,#7Fh
                ANL   PRELST+0,#0EFh      ;cs
                MOV   P1,PRELST+0
                ORL   IE,#80h
                
                MOV   A,B
                LCALL  wrb
                LCALL  wrb
                
                ANL   IE,#7Fh
                ORL   PRELST+0,#10h       ;remove cs
                MOV   P1,PRELST+0
                ORL   IE,#80h
                
                RET



wrt_single: ANL   IE,#7Fh                              
            ANL   PRELST+0,#0EFh    ;slave select
            MOV   P1,PRELST+0                          
            ORL   IE,#80h                                 

            PUSH  ACC                                   
            MOV   A,B                                  
            ORL   A,#80h                                 
            LCALL wrb                                       
            POP   ACC                                     
            LCALL wrb                                       
                   
            ANL   IE,#7Fh  
            ORL   PRELST+0, #10h     ;remove slave select
            MOV   P1, PRELST+0                          
            ORL   IE,#80h                               
               
            RET                                       

            


wrb:         PUSH  ACC
wrb0:        MOV   A,SPSTAT
             ANL   A,#80h
             JNZ   wrb0
             POP   ACC
             MOV   SPDAT,A
herebe:      MOV   A,SPSTAT
             ANL   A,#80h
             JZ    herebe
             MOV   A,SPDAT
             
             RET

本文标签: cI can not read the FIFO of Semtech SX1231Stack Overflow