Rapid GPIO (RGPIO)
10-10
Freescale Semiconductor
MCF51CN128 Reference Manual, Rev. 6
For this example, the processing of the SPI message is considerably more complex than the generation of
a simple square wave of the previous example. The code snippet used to extract the data bit from the
message and build the required GPIO data register writes is shown in
.
# subtest: send a 16-bit message via a SPI interface using a RGPIO
# the SPI protocol uses a 3-bit value: clock, chip-select, data
# the data is centered around the rising-edge of the clock
align 16
send_16b_spi_message_rgpio:
00510: 4fef fff4 lea -12(%sp),%sp # allocate stack space
00514: 48d7 008c movm.l &0x8c,(%sp) # save d2,d3,d7
00518: 3439 0080 0582 mov.w Rmessage2,%d2 # get 16-bit message
0051e: 760f movq.l &15,%d3 # static shift count
00520: 7e10 movq.l &16,%d7 # message bit length
00522: 207c 00c0 0003 mov.l &RGP1,%a0 # pointer to low-order data byte
00528: 203c 0000 ffff mov.l &0xffff,%d0 # data value for _ENB and _DIR regs
0052e: 3140 fffd mov.w %d0,-3(%a0) # set RGPIO_DIR register
00532: 3140 0001 mov.w %d0,1(%a0) # set RGPIO_ENB register
00536: 223c 0001 0000 mov.l &0x10000,%d1 # d1[17:16] = {clk, cs}
0053c: 2001 mov.l %d1,%d0 # copy into temp reg
0053e: e6a8 lsr.l %d3,%d0 # align in d0[2:0]
00540: 5880 addq.l &4,%d0 # set clk = 1
00542: 1080 mov.b %d0,(%a0) # initialize data
00544: 6002 bra.b L%1
align 4
L%1:
00548: 3202 mov.w %d2,%d1 # d1[17:15] = {clk, cs, data}
0054a: 2001 mov.l %d1,%d0 # copy into temp reg
0054c: e6a8 lsr.l %d3,%d0 # align in d0[2:0]
0054e: 1080 mov.b %d0,(%a0) # transmit data with clk = 0
00550: 5880 addq.l &4,%d0 # force clk = 1
00552: e38a lsl.l &1,%d2 # d2[15] = new message data bit
00554: 51fc tpf # preserve 50% duty cycle
00556: 51fc tpf
00558: 51fc tpf
0055a: 51fc tpf
0055c: 1080 mov.b %d0,(%a0) # transmit data with clk = 1
0055e: 5387 subq.l &1,%d7 # decrement loop counter
00560: 66e6 bne.b L%1
00562: c0bc 0000 fff5 and.l &0xfff5,%d0 # negate chip-select
00568: 1080 mov.b %d0,(%a0) # update gpio
0056a: 4cd7 008c movm.l (%sp),&0x8c # restore d2,d3,d7
0056e: 4fef 000c lea 12(%sp),%sp # deallocate stack space
00572: 4e75 rts
Figure 10-9. GPIO SPI Code Example
The resulting SPI performance, as measured in the effective Mbps transmission rate for the 16-bit message,
is shown in