ssi-test.c


1
#include "inc/hw_ints.h"
2
#include "inc/hw_memmap.h"
3
#include "inc/hw_types.h"
4
#include "driverlib/debug.h"
5
#include "driverlib/gpio.h"
6
#include "driverlib/interrupt.h"
7
#include "driverlib/rom.h"
8
#include "driverlib/rom_map.h"
9
#include "driverlib/sysctl.h"
10
#include "driverlib/timer.h"
11
#include "driverlib/uart.h"
12
#include "driverlib/gpio.h"
13
#include "inc/lm3s5y36.h"
14
#include "driverlib/ssi.h"
15
16
17
volatile long lEmpfangeneDatenH=0;
18
volatile long lEmpfangeneDatenL=0;
19
20
/* Hauptprogramm */
21
int main(void)
22
{    
23
  /* Initialisierung */
24
  unsigned long ul_SSIEmpfang;
25
26
  /* Set the clocking to run directly from the crystal. */
27
  SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ);
28
                 
29
  //Enable the needed peripherals
30
  MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);  //PORT A für SSI-Kommunikation
31
  MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);    //SSI-0 Modul
32
  
33
  //SSI_RX als Input (vermutlich nicht benötigt)
34
  GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_4);
35
  //SSI_TX und SSI_CLK als Output (vermutlich nicht benötigt)
36
  GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_5);
37
38
  //PINs SSI0 zuordnen
39
  GPIOPinTypeSSI(GPIO_PORTA_BASE,GPIO_PIN_2 | GPIO_PIN_4 | GPIO_PIN_5);
40
  
41
  //CS-Pins als Output setzen
42
  GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7);  //Pin A6 und Pin A7 für die beiden SSI-Beschleunigungssensoren
43
  
44
  //LIS331HH  deaktivieren (CS jauf High);
45
  GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,GPIO_PIN_6); 
46
  
47
  //SSI konfigurieren
48
  SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_3,  SSI_MODE_MASTER, 20000, 8); //MODE_3 bedeutet Polarity 1 (Clock Idle High) und Phase 1 (Bei der Transistion von Low nach High wird gelesen)
49
  //SSI0 master modul initialisieren
50
  SSIEnable(SSI0_BASE);
51
52
  /* Initialisierung abgeschlossen */
53
  
54
  
55
  /* Los geht's: */
56
  
57
  /* Sensor aktivieren - zugehörigen ChipSelect auf low */
58
  GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,0); 
59
60
  /* Contrl_Reg 1 auswählen */
61
  SSIDataPut(SSI0_BASE,0x20);
62
  /* Warten bis Transfer beendet*/
63
  while(SSIBusy(SSI0_BASE));
64
65
  /* In Control Register 1 0xC4 schreiben zum Aktivieren des Sensors und zum Aktivieren der Z-Achse */
66
  SSIDataPut(SSI0_BASE,0xC4);
67
  /* Warten bis Transfer beendet*/
68
  while(SSIBusy(SSI0_BASE));
69
  
70
  /* Immer wieder Daten lesen*/
71
  while(1)
72
  {
73
    lEmpfangeneDatenL = 0;
74
    lEmpfangeneDatenH = 0;
75
    /* Low-Byte Z-Achse auswählen und Lesebefehl mitschicken*/
76
    SSIDataPut(SSI0_BASE,0xAC);
77
    while(SSIBusy(SSI0_BASE));
78
    /* Register Lesen */
79
    SSIDataGet(SSI0_BASE, &ul_SSIEmpfang);
80
    lEmpfangeneDatenL = ul_SSIEmpfang ;
81
    
82
    /* High-Byte Z-Achse auswählen*/
83
    SSIDataPut(SSI0_BASE,0xAD);
84
    while(SSIBusy(SSI0_BASE));
85
    /* Register Lesen */
86
    SSIDataGet(SSI0_BASE,&ul_SSIEmpfang);
87
    lEmpfangeneDatenH  = ul_SSIEmpfang ;
88
      
89
  }
90
}