cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Visitor
Visitor
2,654 Views
Registered: ‎01-04-2017

Artix 7 DDR 4 Accelerometer register read and write

Hello everyone,

I have been trying to read and write to the FPGA accelerometer. So far I been trying to write to the activity threshold register(value written is 0xFA) then reading from it. It is just a simple step of the many step required to set it up but I cant seem to be able to get the proper values

 

Write 250 decimal (0xFA) to Register 0x20

--My code to write is

 

                -------------give write instruction
                if mosi_8_stop <= 7 then
                    mosi  <= mosi_write_rom(conv_integer(mosi_8_stop)) ;
                    mosi_8_stop <= mosi_8_stop + 1;
                elsif mosi_8_stop > 7 then
                    mosi_8_stop <= "0000";
                    miso_move <= x"3";
                    state <= ST_1b;
                    
                else
                end if;
                
            
            WHEN ST_1b=>
            --------------give write location reg20
                if mosi_8_stop <= 7   then
                    mosi  <= reg_x20(conv_integer(mosi_8_stop)) ;
                    mosi_8_stop <= mosi_8_stop + 1;
                elsif mosi_8_stop > 7 then
                    mosi_8_stop <= "0000";
                    state <= ST_1c;
                else
                end if;
                
                WHEN ST_1c =>
            ----------------------give write data reg20 write FA
                if  mosi_8_stop <= 7 then
                mosi  <= write_FA(conv_integer(mosi_8_stop)) ;
                mosi_8_stop <= mosi_8_stop + 1;
                elsif mosi_8_stop > 7 then
                mosi_8_stop <= "0000";
              
                state <= ST_int_done;
                else
                end if;

 

There is a state machine controling it,ignore that stuff, write_rom and write_FA etc are vectors that contain the bits to be written, the accelerometer communicates via SPI thus I shifted the values bit by bit by clock rising edge. there is a clock divider that lowers it to about 50KHZ for the accelerometer

 

my code for reading is

 

                -------------------------------------------------------------- miso storage, read accelerometer
if read_en = '1' then

    if miso_move = x"C" and read_sent_instruct = '1' then
            
            if miso_8_stop <= 7 then
                miso_X_8(conv_integer(miso_8_stop)) <= miso;
                miso_8_stop <= miso_8_stop + 1;
                
            elsif miso_8_stop > 7 then
                miso_8_stop <= "0000";
                miso_move <= x"A";
            else
            end if;
    else
    end if;




-----------------------------------------------------------------------



    if read_sent_instruct = '0'  then
        if mosi_8_stop > 7 then
            read_sent_instruct <= '1';
            mosi_8_stop <= "0000";
            
            miso_move <= x"E";
        elsif mosi_8_stop <= 7 then
            mosi <= mosi_read_rom(conv_integer( mosi_8_stop) );
            mosi_8_stop <= mosi_8_stop + 1;
        else
        end if;
        
    elsif read_sent_instruct = '1'  and (miso_move = x"E") then
        
        if mosi_8_stop > 7 then
        
            mosi_8_stop <= "0000";
            miso_move <= x"C";
            
        elsif mosi_8_stop <= 7 then
            mosi <= reg_x20(conv_integer (mosi_8_stop) );
            mosi_8_stop <= mosi_8_stop + 1;
            
        end if;
        else
    end if;

else
end if;

 

---------------

 

code is only for reference, you don;t need to look at it if you don;t want to

 

basically I shift in what I need to write and then shift in what I want to read, however the miso always return x"FF" meaning 111111, just a bunch of ones, when I try to read. It is reading, but it is reading junk, I am not sure what I am doing wrong.  CS(slave select) is always 0 since it is active low, I just made it always 0 for testing purposes. I don't think I need to change awake bit to read and write to it do I?

 

Please give a few pointers if you can, thank you.

0 Kudos
0 Replies