Vitaliy Loginov / PGA280_ADS1259

Dependents:   Chromatograph_Mobile Chromatograph_Mobile

Committer:
vitlog
Date:
Mon Jun 08 05:48:24 2020 +0000
Revision:
0:f9ba28ab9f4c
ads1259

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vitlog 0:f9ba28ab9f4c 1 #include "PerifConfig.h"
vitlog 0:f9ba28ab9f4c 2 #include <stdio.h>
vitlog 0:f9ba28ab9f4c 3
vitlog 0:f9ba28ab9f4c 4 /*Переопределение имени пинов*/
vitlog 0:f9ba28ab9f4c 5 DigitalOut Cs(D10);
vitlog 0:f9ba28ab9f4c 6 DigitalOut En1(D15);
vitlog 0:f9ba28ab9f4c 7
vitlog 0:f9ba28ab9f4c 8 DigitalOut Adr0(D5);
vitlog 0:f9ba28ab9f4c 9 DigitalOut Adr1(D6);
vitlog 0:f9ba28ab9f4c 10 DigitalOut Adr2(D7);
vitlog 0:f9ba28ab9f4c 11
vitlog 0:f9ba28ab9f4c 12 DigitalOut Reset(D8);
vitlog 0:f9ba28ab9f4c 13 DigitalIn CrdyA(D9);
vitlog 0:f9ba28ab9f4c 14 /*Конец*/
vitlog 0:f9ba28ab9f4c 15
vitlog 0:f9ba28ab9f4c 16 //MOSI,MISO,SCK
vitlog 0:f9ba28ab9f4c 17 SPI TED2(D11, D12, D13);
vitlog 0:f9ba28ab9f4c 18
vitlog 0:f9ba28ab9f4c 19 Serial UART(SERIAL_TX,SERIAL_RX,NULL,115200);
vitlog 0:f9ba28ab9f4c 20
vitlog 0:f9ba28ab9f4c 21
vitlog 0:f9ba28ab9f4c 22 void UART_gets(char maxcount)
vitlog 0:f9ba28ab9f4c 23 /*Функция получения строки и записи её в глобальную переменную str[]*/
vitlog 0:f9ba28ab9f4c 24 {
vitlog 0:f9ba28ab9f4c 25 int i=0;
vitlog 0:f9ba28ab9f4c 26 do
vitlog 0:f9ba28ab9f4c 27 {
vitlog 0:f9ba28ab9f4c 28 while (UART.readable()); //перед точкой с запятой цикл
vitlog 0:f9ba28ab9f4c 29 str[i++]=UART.getc();
vitlog 0:f9ba28ab9f4c 30 }
vitlog 0:f9ba28ab9f4c 31 while ((str[i-2]!=0x0D)&&(str[i-1]!=0x0A));
vitlog 0:f9ba28ab9f4c 32 for (i=i;i<maxcount;i++)
vitlog 0:f9ba28ab9f4c 33 {
vitlog 0:f9ba28ab9f4c 34 str[i]='\0';
vitlog 0:f9ba28ab9f4c 35 }
vitlog 0:f9ba28ab9f4c 36 }
vitlog 0:f9ba28ab9f4c 37
vitlog 0:f9ba28ab9f4c 38
vitlog 0:f9ba28ab9f4c 39
vitlog 0:f9ba28ab9f4c 40 void DebugString (unsigned char *sData,unsigned char sz)
vitlog 0:f9ba28ab9f4c 41 {
vitlog 0:f9ba28ab9f4c 42 /*
vitlog 0:f9ba28ab9f4c 43 int i;
vitlog 0:f9ba28ab9f4c 44 for (i=0;i<sz;i++)
vitlog 0:f9ba28ab9f4c 45 {
vitlog 0:f9ba28ab9f4c 46 if (sData[i]==0x00) //если пришёл символ конца строки то не отправляем что-либо
vitlog 0:f9ba28ab9f4c 47 {
vitlog 0:f9ba28ab9f4c 48 i=sz;
vitlog 0:f9ba28ab9f4c 49 }
vitlog 0:f9ba28ab9f4c 50 else UART1_Transmit(sData[i]);
vitlog 0:f9ba28ab9f4c 51 }
vitlog 0:f9ba28ab9f4c 52 */
vitlog 0:f9ba28ab9f4c 53 }
vitlog 0:f9ba28ab9f4c 54
vitlog 0:f9ba28ab9f4c 55 void SPI1_MasterInitMode(char mode)
vitlog 0:f9ba28ab9f4c 56 {
vitlog 0:f9ba28ab9f4c 57 TED2.format(8,mode);
vitlog 0:f9ba28ab9f4c 58 TED2.frequency(1000000);
vitlog 0:f9ba28ab9f4c 59 }
vitlog 0:f9ba28ab9f4c 60 void SPI1_SlaveInit()
vitlog 0:f9ba28ab9f4c 61 {
vitlog 0:f9ba28ab9f4c 62
vitlog 0:f9ba28ab9f4c 63 }
vitlog 0:f9ba28ab9f4c 64
vitlog 0:f9ba28ab9f4c 65
vitlog 0:f9ba28ab9f4c 66 void SPI1MasterTransmitString(unsigned char *sData,unsigned int sz) //передать строку размером sz
vitlog 0:f9ba28ab9f4c 67 {
vitlog 0:f9ba28ab9f4c 68 /*
vitlog 0:f9ba28ab9f4c 69 int i=0;
vitlog 0:f9ba28ab9f4c 70 for (i=0;i<sz;i++)
vitlog 0:f9ba28ab9f4c 71 {
vitlog 0:f9ba28ab9f4c 72 SPI1MasterTransferByte(sData[i]);
vitlog 0:f9ba28ab9f4c 73 }
vitlog 0:f9ba28ab9f4c 74 */
vitlog 0:f9ba28ab9f4c 75 }
vitlog 0:f9ba28ab9f4c 76
vitlog 0:f9ba28ab9f4c 77 unsigned char SPI1MasterTransferByte(unsigned char cData)//отправить и считать байт
vitlog 0:f9ba28ab9f4c 78 {
vitlog 0:f9ba28ab9f4c 79 return TED2.write(cData);
vitlog 0:f9ba28ab9f4c 80 }
vitlog 0:f9ba28ab9f4c 81
vitlog 0:f9ba28ab9f4c 82 unsigned char SPI1MasterReadByte()
vitlog 0:f9ba28ab9f4c 83 {
vitlog 0:f9ba28ab9f4c 84 return TED2.write(0xFF);
vitlog 0:f9ba28ab9f4c 85 }