|
@@ -5,6 +5,7 @@
|
|
|
#include "settings_api.h"
|
|
|
#include "io_utils.h"
|
|
|
#include "adc_transport.h"
|
|
|
+#include "misc.h"
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
@@ -105,6 +106,7 @@ unsigned char SPI_Init(unsigned char lsbFirst,
|
|
|
return(1);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/***************************************************************************//**
|
|
|
* @brief Writes data to SPI.
|
|
|
*
|
|
@@ -115,57 +117,36 @@ unsigned char SPI_Init(unsigned char lsbFirst,
|
|
|
*
|
|
|
* @return Number of written bytes.
|
|
|
*******************************************************************************/
|
|
|
-unsigned char SPI_Write(unsigned char* data,
|
|
|
- unsigned char bytesNumber)
|
|
|
+unsigned char SPI_Write(unsigned char* data, unsigned char bytesNumber)
|
|
|
{
|
|
|
- unsigned char readData[4] = {0, 0, 0, 0};
|
|
|
+ unsigned char chipSelect = data[0];
|
|
|
+ unsigned char writeData[4] = {0, 0, 0, 0};
|
|
|
+ unsigned char readData[4] = {0, 0, 0, 0};
|
|
|
+
|
|
|
+ if (chipSelect == 1)
|
|
|
+ MS5192T_CS_LOW;
|
|
|
+
|
|
|
+ for (unsigned char byte = 0; byte < bytesNumber; byte++)
|
|
|
+ {
|
|
|
+ writeData[byte] = data[byte + 1];
|
|
|
+ }
|
|
|
|
|
|
for (int i = 0; i < bytesNumber; i++)
|
|
|
{
|
|
|
while (spi_i2s_flag_get(MS5192T_SPI, SPI_I2S_TDBE_FLAG) == RESET);
|
|
|
- MS5192T_SPI->dt = data[i];
|
|
|
+ MS5192T_SPI->dt = writeData[i];
|
|
|
|
|
|
while (spi_i2s_flag_get(MS5192T_SPI, SPI_I2S_RDBF_FLAG) == RESET);
|
|
|
readData[i] = MS5192T_SPI->dt;
|
|
|
}
|
|
|
-#if 0
|
|
|
- unsigned char chipSelect = data[0];
|
|
|
- unsigned char writeData[4] = {0, 0, 0, 0};
|
|
|
- unsigned char readData[4] = {0, 0, 0, 0};
|
|
|
- unsigned char byte = 0;
|
|
|
|
|
|
- for(byte = 0;byte < bytesNumber;byte ++)
|
|
|
- {
|
|
|
- writeData[byte] = data[byte + 1];
|
|
|
- }
|
|
|
- if(chipSelect == 1)
|
|
|
- {
|
|
|
- ADI_PART_CS_LOW;
|
|
|
- }
|
|
|
- if(chipSelect == 2)
|
|
|
- {
|
|
|
- ST7579_CS_LOW;
|
|
|
- }
|
|
|
- for(byte = 0;byte < bytesNumber;byte ++)
|
|
|
- {
|
|
|
- R_CSI10_Send_Receive((uint8_t *)&writeData[byte],
|
|
|
- 1,
|
|
|
- (uint8_t *)readData);
|
|
|
- while(CSIIF10 == 0);
|
|
|
- }
|
|
|
- if(chipSelect == 1)
|
|
|
- {
|
|
|
- ADI_PART_CS_HIGH;
|
|
|
- }
|
|
|
- if(chipSelect == 2)
|
|
|
- {
|
|
|
- ST7579_CS_HIGH;
|
|
|
- }
|
|
|
-
|
|
|
- return(bytesNumber);
|
|
|
-#endif
|
|
|
+ if (chipSelect == 1)
|
|
|
+ MS5192T_CS_HIGH;
|
|
|
+
|
|
|
+ return bytesNumber;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/***************************************************************************//**
|
|
|
* @brief Reads data from SPI.
|
|
|
*
|
|
@@ -178,22 +159,23 @@ unsigned char SPI_Write(unsigned char* data,
|
|
|
*
|
|
|
* @return Number of written bytes.
|
|
|
*******************************************************************************/
|
|
|
-unsigned char SPI_Read(unsigned char* data,
|
|
|
- unsigned char bytesNumber)
|
|
|
+unsigned char SPI_Read(unsigned char* data, unsigned char bytesNumber)
|
|
|
{
|
|
|
- unsigned char writeData[4] = {0, 0, 0, 0};
|
|
|
- unsigned char readData[4] = {0, 0, 0, 0};
|
|
|
- unsigned char byte = 0;
|
|
|
+ unsigned char chipSelect = data[0];
|
|
|
+ unsigned char writeData[4] = {0, 0, 0, 0};
|
|
|
+ unsigned char readData[4] = {0, 0, 0, 0};
|
|
|
+ unsigned char byte = 0;
|
|
|
|
|
|
- for(byte = 0;byte < bytesNumber;byte ++)
|
|
|
+ for (byte = 0; byte < bytesNumber; byte++)
|
|
|
{
|
|
|
writeData[byte] = data[byte + 1];
|
|
|
data[byte + 1] = 0;
|
|
|
}
|
|
|
|
|
|
- MS5192T_CS_LOW;
|
|
|
+ if (chipSelect == 1)
|
|
|
+ MS5192T_CS_LOW;
|
|
|
|
|
|
- for(byte = 0;byte < bytesNumber;byte ++)
|
|
|
+ for (byte = 0; byte < bytesNumber; byte++)
|
|
|
{
|
|
|
while (spi_i2s_flag_get(MS5192T_SPI, SPI_I2S_TDBE_FLAG) == RESET);
|
|
|
MS5192T_SPI->dt = writeData[byte];
|
|
@@ -202,56 +184,15 @@ unsigned char SPI_Read(unsigned char* data,
|
|
|
readData[byte] = MS5192T_SPI->dt;
|
|
|
}
|
|
|
|
|
|
- MS5192T_CS_HIGH;
|
|
|
+ if (chipSelect == 1)
|
|
|
+ MS5192T_CS_HIGH;
|
|
|
|
|
|
- for(byte = 0;byte < bytesNumber;byte ++)
|
|
|
+ for (byte = 0; byte < bytesNumber; byte++)
|
|
|
{
|
|
|
data[byte] = readData[byte];
|
|
|
}
|
|
|
|
|
|
- return(bytesNumber);
|
|
|
-
|
|
|
-#if 0
|
|
|
- unsigned char chipSelect = data[0];
|
|
|
- unsigned char writeData[4] = {0, 0, 0, 0};
|
|
|
- unsigned char readData[4] = {0, 0, 0, 0};
|
|
|
- unsigned char byte = 0;
|
|
|
-
|
|
|
- for(byte = 0;byte < bytesNumber;byte ++)
|
|
|
- {
|
|
|
- writeData[byte] = data[byte + 1];
|
|
|
- data[byte + 1] = 0;
|
|
|
- }
|
|
|
- if(chipSelect == 1)
|
|
|
- {
|
|
|
- ADI_PART_CS_LOW;
|
|
|
- }
|
|
|
- if(chipSelect == 2)
|
|
|
- {
|
|
|
- ST7579_CS_LOW;
|
|
|
- }
|
|
|
- for(byte = 0;byte < bytesNumber;byte ++)
|
|
|
- {
|
|
|
- R_CSI10_Send_Receive((uint8_t *)&writeData[byte],
|
|
|
- 1,
|
|
|
- (uint8_t *)&readData[byte]);
|
|
|
- while(CSIIF10 == 0);
|
|
|
- }
|
|
|
- if(chipSelect == 1)
|
|
|
- {
|
|
|
- ADI_PART_CS_HIGH;
|
|
|
- }
|
|
|
- if(chipSelect == 2)
|
|
|
- {
|
|
|
- ST7579_CS_HIGH;
|
|
|
- }
|
|
|
- for(byte = 0;byte < bytesNumber;byte ++)
|
|
|
- {
|
|
|
- data[byte] = readData[byte];
|
|
|
- }
|
|
|
-
|
|
|
- return(bytesNumber);
|
|
|
-#endif
|
|
|
+ return bytesNumber;
|
|
|
}
|
|
|
|
|
|
//
|
|
@@ -259,14 +200,41 @@ void adc_task(void *params)
|
|
|
{
|
|
|
bool state = false;
|
|
|
unsigned long value;
|
|
|
+ uint8_t ret;
|
|
|
+
|
|
|
+ vTaskDelay(1000);
|
|
|
|
|
|
adc_gpio_init();
|
|
|
|
|
|
MS5192T_Reset();
|
|
|
|
|
|
+ ret = MS5192T_Init();
|
|
|
+
|
|
|
+ printf("ADC init status: %s\r\n", ret == 1 ? "OK" : "FAILED");
|
|
|
+
|
|
|
+ // Запрос регистра конфигурации для (0x710 - значение по умолчанию)
|
|
|
+ value = MS5192T_GetRegisterValue(MS5192T_REG_CONF, 2, 1);
|
|
|
+ printf("ADC configuretion register: 0x%X\r\n", value);
|
|
|
+
|
|
|
+ // Коэф-т усиления: 1
|
|
|
+ printf("ADC. Set gain rate: %u\r\n", (uint8_t)MS5192T_GAIN_1);
|
|
|
+ MS5192T_SetGain(MS5192T_GAIN_1);
|
|
|
+ value = MS5192T_GetRegisterValue(MS5192T_REG_CONF, 2, 1);
|
|
|
+ printf("ADC configuretion register: 0x%X, gain rate = %u (value 0 eq 1 gain rate)\r\n",
|
|
|
+ value, (value & 0x700) >> 8);
|
|
|
+
|
|
|
+ printf("Set unipolar input mode.\r\n");
|
|
|
+ MS5192T_SetPolar(MS5192T_CONF_UNIPOLAR);
|
|
|
+ value = MS5192T_GetRegisterValue(MS5192T_REG_CONF, 2, 1);
|
|
|
+ printf("ADC configuretion register: 0x%X, polar bit: %u\r\n", value, (value & 0x1000) >> 12);
|
|
|
+
|
|
|
+
|
|
|
for (;;)
|
|
|
{
|
|
|
- if (state == false) {
|
|
|
+
|
|
|
+#if 0
|
|
|
+ if (state == false)
|
|
|
+ {
|
|
|
if (MS5192T_Init() == 1)
|
|
|
{
|
|
|
vTaskDelay(2000);
|
|
@@ -298,7 +266,7 @@ void adc_task(void *params)
|
|
|
}
|
|
|
|
|
|
printf("Value: %u\r\n", value);
|
|
|
-
|
|
|
+#endif
|
|
|
vTaskDelay(1000);
|
|
|
}
|
|
|
}
|