1 | #pragma udata
|
2 | unsigned char SI470xdata[31]; // Commandopacket für SI4701
|
3 |
|
4 | //
|
5 | #pragma code
|
6 | /******************************************************************************
|
7 | * Function: void InitSI470x(void)
|
8 | *
|
9 | * PreCondition: None
|
10 | *
|
11 | * Input: None
|
12 | *
|
13 | * Output: None
|
14 | *
|
15 | * Side Effects: None
|
16 | *
|
17 | * Overview: Enables the SI470x
|
18 | *
|
19 | * Note: None
|
20 | *****************************************************************************/
|
21 | void SI470xInit(void)
|
22 | {
|
23 | SSP2CON1bits.SSPEN = 0; // I2C for startup as IO
|
24 | TRISDbits.TRISD5 = 0; // output
|
25 | TRISDbits.TRISD6 = 0; // output
|
26 | TRISBbits.TRISB4 = 0; // output
|
27 | LATDbits.LATD5 = 0; //
|
28 | LATDbits.LATD6 = 0;
|
29 | LATBbits.LATB4 = 0; // SI4701 reset, GPIO3 automatically low by internal pulldown
|
30 | Delay1KTCYx(10);
|
31 | LATBbits.LATB4 = 1; // SI4701 start, wait for Powerup
|
32 | Delay1KTCYx(10); // SDO MUST BE LOW DURING THIS PERIOD
|
33 | TRISDbits.TRISD5 = 1; // input again
|
34 | TRISDbits.TRISD6 = 1; // input again
|
35 | T1CON = 0x4B; // T1 OSC, OSC EN, start reference clock
|
36 | I2CStart();
|
37 | I2CTransmit(SI470x_write);
|
38 | I2CAckTx();
|
39 | I2CTransmit(0x40); // See AN230
|
40 | I2CAckTx();
|
41 | I2CTransmit(0x01); // Reg 0x2: Enable, demute
|
42 | I2CAckTx();
|
43 | I2CStop();
|
44 | Delay10KTCYx(132); // wait 110ms until powerup is complete
|
45 | SI470xClearData();
|
46 | // Init Array with correct values
|
47 | SI470xdata[Powercfg_h] = SI47_DMUTE;
|
48 | SI470xdata[Powercfg_l] = SI47_ENABLE;
|
49 | SI470xdata[Channel_h] = !SI47_TUNE;
|
50 | SI470xdata[Sysconfig1_h] = SI47_RDS | SI47_DE;
|
51 | SI470xdata[Sysconfig1_l] = SI47_BLNDADJ_DEF | SI47_GPIO3_HI | SI47_GPIO2_LO | SI47_GPIO1_HI;
|
52 | SI470xdata[Sysconfig2_h] = SI47_SEEKTH;
|
53 | SI470xdata[Sysconfig2_l] = SI47_BAND_USA_EUR | SI47_SPACE_100KHZ | SI47_VOLUME;
|
54 | SI470xdata[Sysconfig3_h] = SI47_SMUTER_FASTEST | SI47_SMUTEA_16DB;
|
55 | SI470xdata[Sysconfig3_l] = SI47_SKSNR | SI47_SKCNT;
|
56 | SI470xSend();
|
57 | Delay1TCY();
|
58 | SI470xRead(); // Status, IDs, etc
|
59 | }
|
60 |
|
61 | /******************************************************************************
|
62 | * Function: void SendSI470x(void)
|
63 | *
|
64 | * PreCondition: Arry with Command is properly initialised
|
65 | *
|
66 | * Input: Array SI470xdata with commands
|
67 | *
|
68 | * Output: None
|
69 | *
|
70 | * Side Effects: None
|
71 | *
|
72 | * Overview: Send packet of commands to SI470x
|
73 | *
|
74 | * Note: None
|
75 | *****************************************************************************/
|
76 | void SI470xSend(void)
|
77 | {
|
78 | unsigned char i;
|
79 | I2CStart();
|
80 | I2CTransmit(SI470x_write);
|
81 | I2CAckTx();
|
82 | for (i=0; i < 10; i++)
|
83 | {
|
84 | I2CTransmit(SI470xdata[Powercfg_h+i]); //
|
85 | I2CAckTx(); //
|
86 | }
|
87 | I2CStop();
|
88 | }
|
89 |
|
90 | /******************************************************************************
|
91 | * Function: void ReadSI470x(void)
|
92 | *
|
93 | * PreCondition: None
|
94 | *
|
95 | * Input: Array SI470xdata will be updated with read-only values
|
96 | *
|
97 | * Output: None
|
98 | *
|
99 | * Side Effects: None
|
100 | *
|
101 | * Overview: Read From
|
102 | *
|
103 | * Note: None
|
104 | *****************************************************************************/
|
105 | void SI470xRead(void)
|
106 | {
|
107 | unsigned char i;
|
108 | I2CStart();
|
109 | I2CTransmit(SI470x_read);
|
110 | I2CAckTx();
|
111 | for(i=0; i<12; i++)
|
112 | {
|
113 | SI470xdata[i+StatusRSSI_h] = I2CReceive(); // read beginns on register 10
|
114 | I2CAckRx();
|
115 | }
|
116 | for(i=0; i<4; i++) // Array is only 32Byte
|
117 | { // To wrap araound, new read cycle is needed
|
118 | SI470xdata[i] = I2CReceive();
|
119 | I2CAckRx();
|
120 | }
|
121 | I2CReceive(); //dummyread without Ack to end transmission
|
122 | I2CNAckRx();
|
123 | I2CStop();
|
124 | }
|