Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/17/05 14:26
Read: times


 
#95167 - re:SPI
Responding to: ???'s previous message
Drew,

Here is code from Atmel's code library:

Hope it helps, try this code first to make sure you have no hardware problems, then if it works, then look at how Atmel uses the SPI link in their software to get some clues about how to use their SPI link.

Jacob


<PRE>

$INCLUDE (reg_c51.INC)

transmit_completed BIT 20H.1; software flag
serial_data DATA 08H
data_save DATA 09H
data_example DATA 0AH;

org 000h
ljmp begin

org 4Bh
ljmp it_SPI

;/**
; * FUNCTION_PURPOSE: This file set up spi in master mode with
; * Fclk Periph/128 as baud rate and with slave select pin.
; * FUNCTION_INPUTS: P1.5(MISO) serial input
; * FUNCTION_OUTPUTS: P1.7(MOSI) serial output
; */

org 0100h
begin:
;init
MOV data_example,#55h; /* data example */
ORL SPCON,#10h; /* Master mode */
SETB P1.1; /* enable master */
ORL SPCON,#82h; /* Fclk Periph/128 */
ANL SPCON,#0F7h; /* CPOL=0; transmit mode example */
ORL SPCON,#04h; /* CPHA=1; transmit mode example */
ORL IEN1,#04h; /* enable spi interrupt */
ORL SPCON,#40h; /* run spi */
CLR transmit_completed; /* clear software transfert flag */
SETB EA; /* enable interrupts */
loop: /* endless */

MOV SPDAT,data_example; /* send an example data */
JNB transmit_completed,$; /* wait end of transmition */
CLR transmit_completed; /* clear software transfert flag */
MOV SPDAT,#00h; /* data is send to generate SCK signal */
JNB transmit_completed,$; /* wait end of transmition */
CLR transmit_completed; /* clear software transfert flag */
MOV data_save,serial_data; /* save receive data */
LJMP loop



List of 10 messages in thread
TopicAuthorDate
8052-to-8052 SPI Communication            01/01/70 00:00      
   glad that you do            01/01/70 00:00      
      8052-to-8052 SPI Communication            01/01/70 00:00      
         an obvious guess            01/01/70 00:00      
            an obvious guess            01/01/70 00:00      
               a question            01/01/70 00:00      
                  a question            01/01/70 00:00      
                     as the first byte from the slave            01/01/70 00:00      
   more questions            01/01/70 00:00      
   re:SPI            01/01/70 00:00      

Back to Subject List