Project

General

Profile

Revision 752

fixed lost of bugs in the libraries for spi and encoder

View differences:

spi.c
10 10
#include <dragonfly_lib.h>
11 11
#include "spi.h"
12 12

  
13

  
13 14
static volatile char spi_bytes; /* number of bytes to read */
14 15
static spi_fun_recv_t spi_recv_func; /* byte handler */
15 16
static spi_fun_recv_complete_t spi_recv_complete_func; /*transmission completion handler */
......
17 18
void spi_init (spi_fun_recv_t recv_func, spi_fun_recv_complete_t recv_complete_func)
18 19
{
19 20
    /*  Enable Interrupt, Enable SPI Module, MSB First, Master Mode, Clock div = 64 */
20
    SPCR = _BV(SPE) | _BV(SPIE) | _BV(DORD) | _BV(MSTR) | _BV(SPR1) | _BV(SPR0);
21
  SPCR = _BV(SPE) | _BV(SPIE) /*| _BV(DORD)*/ | _BV(MSTR) | _BV(SPR1) | _BV(SPR0);
21 22
    SPSR = _BV(SPI2X); 
22 23

  
23 24
    /* Set SCLK, SS, MOSI as outputs. MISO as input */
24
    DDRB = MOSI | SCLK | SS;
25
    DDRB |= MOSI | SCLK | SS;
25 26
    DDRB &= ~MISO;
26 27
    
27 28
    /* Keep SS high until transmit */
......
47 48
    /* only handle intterupt when we are expecting data */
48 49
    if(spi_bytes > 0){
49 50
	/* process byte */
50
	spi_recv_func(SPDR);
51
      spi_recv_func(SPDR);
51 52
	/* if we've read all the bytes, set SS high to end transmission,
52 53
	 * otherwise get the next byte  */
53 54
	if(--spi_bytes == 0){
54 55
		//usb_puts("Read all bytes\r\n");
55 56
	    PORTB |= SS;
56
		spi_recv_complete_func();
57
	    if(spi_recv_complete_func)
58
	      spi_recv_complete_func();
57 59
	}else {
58 60
		//usb_puts("There are this many bytes left: "); usb_puti(spi_bytes);usb_puts("\r\n");
59 61
	    SPDR = 0xff;

Also available in: Unified diff