I am reaching out to seek assistance regarding some challenges I am facing with the write and read operations on the SRAM of the AD9106 devices. I have thoroughly studied the respective datasheets (AD9106 datasheet, pages 22-23) but have encountered difficulties in achieving the desired functionality.
Specifically, I am experiencing issues with:
Writing data to the SRAM: Despite following the instructions provided in the datasheets (e.g., enabling the MEM_ACCESS bit in the 0x1E register, writing left-justified data to the SRAM registers ranging from 0x6000 to 0x6FFF, and disabling the MEM_ACCESS bit), I have been unable to successfully write data to the SRAM.
Reading data from the SRAM: Similarly, when attempting to read data from the SRAM, I have encountered difficulties despite enabling the BUF_READ and MEM_ACCESS bits in the 0x1E register. Disabling the bits after reading the data has also proven challenging.
I have thoroughly reviewed the datasheets, but it appears that I may be missing some crucial steps or misinterpreting certain instructions. I would greatly appreciate it if you could provide me with guidance and clarification on the correct procedure for performing write and read operations on the SRAM of the AD9106 devices.
If possible, could you please provide me with detailed step-by-step instructions, highlighting any potential pitfalls or commonly overlooked aspects of the process? Additionally, if there are any specific register settings or considerations I should be aware of, kindly provide those details as well.
I understand that your team has extensive expertise in working with these devices, and I am confident that your guidance will help me overcome the challenges I am currently facing.
Thank you very much for your time and attention to this matter. I look forward to your prompt response and assistance. I attached my code along with it
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdio.h>
#include "IO.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
#ifdef __GNUC__
/* With GCC, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#ifndef HSEM_ID_0
#define HSEM_ID_0 (0U) /* HW semaphore 0*/
#endif
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
I2C_HandleTypeDef hi2c3;
SPI_HandleTypeDef hspi4;
TIM_HandleTypeDef htim2;
UART_HandleTypeDef huart2;
/* USER CODE BEGIN PV */
extern void UNREAD_DAC(uint16_t addr, uint16_t value,uint16_t Read_addr);
extern void DAC(void);
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_I2C3_Init(void);
static void MX_SPI4_Init(void);
static void MX_USART2_UART_Init(void);
static void MX_TIM2_Init(void);
/* USER CODE BEGIN PFP */
extern void DAC(void);
extern void UNREAD_DAC(uint16_t addr, uint16_t value,uint16_t Read_addr);
uint16_t UNREAD_DACW[]={0x0029,0x001E,0x0026,0x002E};
uint16_t UNREAD_DACR[]={0x8029,0x0001,0x0101,0x3FF8};
uint16_t UNREAD_DACV[]={0xFFFF,0x801E,0x8026,0x802E};
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
void delay_us (uint16_t us)
{
__HAL_TIM_SET_COUNTER(&htim2,0); // set the counter value a 0
while (__HAL_TIM_GET_COUNTER(&htim2) < us); // wait for the counter to reach the us input in the parameter
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* USER CODE BEGIN Boot_Mode_Sequence_0 */
int32_t timeout;
/* USER CODE END Boot_Mode_Sequence_0 */
/* USER CODE BEGIN Boot_Mode_Sequence_1 */
/* Wait until CPU2 boots and enters in stop mode or timeout*/
timeout = 0xFFFF;
while((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) != RESET) && (timeout-- > 0));
if ( timeout < 0 )
{
Error_Handler();
}
/* USER CODE END Boot_Mode_Sequence_1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN Boot_Mode_Sequence_2 */
/* When system initialization is finished, Cortex-M7 will release Cortex-M4 by means of
HSEM notification */
/*HW semaphore Clock enable*/
__HAL_RCC_HSEM_CLK_ENABLE();
/*Take HSEM */
HAL_HSEM_FastTake(HSEM_ID_0);
/*Release HSEM in order to notify the CPU2(CM4)*/
HAL_HSEM_Release(HSEM_ID_0,0);
/* wait until CPU2 wakes up from stop mode */
timeout = 0xFFFF;
while((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) == RESET) && (timeout-- > 0));
if ( timeout < 0 )
{
Error_Handler();
}
/* USER CODE END Boot_Mode_Sequence_2 */
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_I2C3_Init();
MX_SPI4_Init();
MX_USART2_UART_Init();
MX_TIM2_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start(&htim2);
remotepinMode(DAC1_RST,OUTPUT); //here we use that reset pin of DAC
remotedigitalWrite(DAC1_RST, HIGH);
HAL_GPIO_WritePin(GPIOH, Trigger2_Pin|Trigger1_Pin, GPIO_PIN_SET); // TRigger
HAL_GPIO_WritePin(CS2_GPIO_Port, CS2_Pin, GPIO_PIN_SET); //Cs2
HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET); // cs1
remotedigitalWrite(DAC1_RST, LOW); // step 3 here we use it
HAL_Delay(10); //5msec delay for reset
remotedigitalWrite(DAC1_RST, HIGH);
printf("------------------------------------------------------------------\n\r");
/* uint8_t i=0,j=0,k=0;
for(i=0,j=0,k=0;i<2;i++,j++,k++)
{
UNREAD_DAC(UNREAD_DACW[i],UNREAD_DACR[j],UNREAD_DACV[k]);
HAL_Delay(10);
}*/
//HAL_GPIO_WritePin(GPIOH, Trigger1_Pin, GPIO_PIN_RESET);
uint16_t addr=0x0034,Read_Value=0;
uint16_t Radd=0x8034,valu=0x4000;
uint8_t s=0,s1=0,s2=0,s3=0;
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
DAC();
/* addr=0x0034,Read_Value=0;
Radd=0x8034,valu=0x4000;
HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
s=HAL_SPI_Transmit(&hspi4, (uint8_t*)&addr, 1, 100);
s1=HAL_SPI_Transmit(&hspi4,(uint8_t*)&valu, 1, 100);
HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);
printf("s=%d s=%d W- A=%x, V=%x\n\r",s,s1,addr,valu);
HAL_Delay(100);
HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
s2=HAL_SPI_Transmit(&hspi4, (uint8_t*)&Radd, 1, 100);
s3=HAL_SPI_Receive(&hspi4,(uint8_t*)&Read_Value,1, 100);
HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);
printf("s=%d s=%d R- A=%x,V=%x\n\n\r",s2,s3,Radd,Read_Value);*/
// delay_us(50); //ethun kh///////////////////////////////////
// HAL_Delay(500);
// addr=0x001E,Read_Value=0;
// Radd=0x801E,valu=0x0001;
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
// s=HAL_SPI_Transmit(&hspi4, (uint8_t*)&addr, 1, 100);
// s1=HAL_SPI_Transmit(&hspi4,(uint8_t*)&valu, 1, 100);
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);
// printf("1s=%d s=%d W- A=%x, V=%x\n\r",s,s1,addr,valu);
// delay_us(50);
//// HAL_Delay(500);
//
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
// s2=HAL_SPI_Transmit(&hspi4, (uint8_t*)&Radd, 1, 100);
// s3=HAL_SPI_Receive(&hspi4,(uint8_t*)&Read_Value,1, 100);
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);
// printf("2s=%d s=%d R- A=%x,V=%x\n\n\r",s2,s3,Radd,Read_Value);
// delay_us(50);
//// HAL_Delay(500);
// s=0,s1=0,s2=0,s3=0;
// Read_Value=0;
// HAL_GPIO_WritePin(GPIOH, Trigger1_Pin, GPIO_PIN_RESET);
// delay_us(1000);
// //HAL_Delay(10000);
// HAL_GPIO_WritePin(GPIOH, Trigger1_Pin, GPIO_PIN_SET);
///////////////////////////////////////////////////////////////////////////////////////////////
//
// addr=0x001E,Read_Value=0;
// Radd=0x801E,valu=0x0004;
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
// s=HAL_SPI_Transmit(&hspi4, (uint8_t*)&addr, 1, 100);
// s1=HAL_SPI_Transmit(&hspi4,(uint8_t*)&valu, 1, 100);
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);
// printf("1s=%d s=%d W- A=%x, V=%x\n\r",s,s1,addr,valu);
// delay_us(50);
// // HAL_Delay(500);
//
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
// s2=HAL_SPI_Transmit(&hspi4, (uint8_t*)&Radd, 1, 100);
// s3=HAL_SPI_Receive(&hspi4,(uint8_t*)&Read_Value,1, 100);
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);
// printf("2s=%d s=%d R- A=%x,V=%x\n\n\r",s2,s3,Radd,Read_Value);
// delay_us(50);
// // HAL_Delay(500);
// s=0,s1=0,s2=0,s3=0;
// Read_Value=0;
// // HAL_GPIO_WritePin(GPIOH, Trigger1_Pin, GPIO_PIN_RESET);
// // delay_us(1000);
// // //HAL_Delay(10000);
// // HAL_GPIO_WritePin(GPIOH, Trigger1_Pin, GPIO_PIN_SET);
//
//
//
//
// addr=0x001E,Read_Value=0;
// Radd=0x801E,valu=0x000C;
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
// s=HAL_SPI_Transmit(&hspi4, (uint8_t*)&addr, 1, 100);
// s1=HAL_SPI_Transmit(&hspi4,(uint8_t*)&valu, 1, 100);
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);
// printf("1s=%d s=%d W- A=%x, V=%x\n\r",s,s1,addr,valu);
// delay_us(50);
// // HAL_Delay(500);
//
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
// s2=HAL_SPI_Transmit(&hspi4, (uint8_t*)&Radd, 1, 100);
// s3=HAL_SPI_Receive(&hspi4,(uint8_t*)&Read_Value,1, 100);
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);
// printf("2s=%d s=%d R- A=%x,V=%x\n\n\r==============================================================================================================================",s2,s3,Radd,Read_Value);
// delay_us(50);
// HAL_Delay(5000);
// s=0,s1=0,s2=0,s3=0;
// Read_Value=0;
//// HAL_GPIO_WritePin(GPIOH, Trigger1_Pin, GPIO_PIN_RESET);
//// delay_us(1000);
//// //HAL_Delay(10000);
//// HAL_GPIO_WritePin(GPIOH, Trigger1_Pin, GPIO_PIN_SET);
//
//
////
//// addr=0x001E,Read_Value=0;
//// Radd=0x801E,valu=0x0000;
//// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
//// s=HAL_SPI_Transmit(&hspi4, (uint8_t*)&addr, 1, 100);
//// s1=HAL_SPI_Transmit(&hspi4,(uint8_t*)&valu, 1, 100);
//// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);
//// printf("ps=%d s=%d W- A=%x, V=%x\n\r",s,s1,addr,valu);
//// delay_us(50);
//// // HAL_Delay(500);
////
//// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
//// s2=HAL_SPI_Transmit(&hspi4, (uint8_t*)&Radd, 1, 100);
//// s3=HAL_SPI_Receive(&hspi4,(uint8_t*)&Read_Value,1, 100);
//// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);
//// printf("rs=%d s=%d R- A=%x,V=%x\n\n\r",s2,s3,Radd,Read_Value);
//// delay_us(50);
//// // HAL_Delay(500);
//// s=0,s1=0,s2=0,s3=0;
//// Read_Value=0;
////// HAL_GPIO_WritePin(GPIOH, Trigger1_Pin, GPIO_PIN_RESET);
////// delay_us(1000);
////// //HAL_Delay(10000);
////// HAL_GPIO_WritePin(GPIOH, Trigger1_Pin, GPIO_PIN_SET);
////
////
//
// addr=0x001E,Read_Value=0;
// Radd=0x801E,valu=0x0001;
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
// s=HAL_SPI_Transmit(&hspi4, (uint8_t*)&addr, 1, 100);
// s1=HAL_SPI_Transmit(&hspi4,(uint8_t*)&valu, 1, 100);
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);
// printf("as=%d s=%d W- A=%x, V=%x\n\r",s,s1,addr,valu);
// delay_us(50);
// // HAL_Delay(500);
////
// addr=0x001D,Read_Value=0;
// Radd=0x801D,valu=0X0001;
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
// s=HAL_SPI_Transmit(&hspi4, (uint8_t*)&addr, 1, 100);
// s1=HAL_SPI_Transmit(&hspi4,(uint8_t*)&valu, 1, 100);
// //HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET); MW COO
// printf("1s=%d s=%d W- A=%x, V=%x\n\r",s,s1,addr,valu);
// delay_us(50);
// // HAL_Delay(500);
////
//// addr=0x0000,Read_Value=0;
//// Radd=0x8000,valu=0X0001;
//// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
//// s=HAL_SPI_Transmit(&hspi4, (uint8_t*)&addr, 1, 100);
//// s1=HAL_SPI_Transmit(&hspi4,(uint8_t*)&valu, 1, 100);
//// //HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET); MW COO
//// printf("1s=%d s=%d W- A=%x, V=%x\n\r",s,s1,addr,valu);
//// delay_us(50);
////
////
////
//// uint8_t e=0,f=0;
////
//// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
//// s2=HAL_SPI_Transmit(&hspi4, (uint8_t*)&Radd, 1, 100);
//// s3=HAL_SPI_Receive(&hspi4,(uint8_t*)&Read_Value,1, 100);
//// //HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET); ME COM
//// printf("ss=%d s=%d R- A=%x,V=%x\n\n\r",s2,s3,Radd,Read_Value);
//// delay_us(50);
//// // HAL_Delay(500);
//// s=0,s1=0,s2=0,s3=0;
//// //Read_Value3=0;
//// //e=HAL_SPI_Receive(&hspi4,(uint8_t*)&Read_Value3,1, 100);
//// HAL_GPIO_WritePin(GPIOH, Trigger1_Pin, GPIO_PIN_RESET);
//// delay_us(1000);
//// //HAL_Delay(10000);
//// //HAL_GPIO_WritePin(GPIOH, Trigger1_Pin, GPIO_PIN_SET);
//
//
// HAL_GPIO_WritePin(GPIOH,Trigger1_Pin, GPIO_PIN_RESET);
// delay_us(500);
// // HAL_Delay(5000);
// HAL_GPIO_WritePin(GPIOH,Trigger1_Pin, GPIO_PIN_SET);
// addr=0x001E,Read_Value=0;
// Radd=0x801E,valu=0x0004;
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
// s=HAL_SPI_Transmit(&hspi4, (uint8_t*)&addr, 1, 100);
// s1=HAL_SPI_Transmit(&hspi4,(uint8_t*)&valu, 1, 100);
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);
// printf("1s=%d s=%d W- A=%x, V=%x\n\r",s,s1,addr,valu);
// delay_us(50);
// // HAL_Delay(500);
//
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
// s2=HAL_SPI_Transmit(&hspi4, (uint8_t*)&Radd, 1, 100);
// s3=HAL_SPI_Receive(&hspi4,(uint8_t*)&Read_Value,1, 100);
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);
// printf("2s=%d s=%d R- A=%x,V=%x\n\n\r",s2,s3,Radd,Read_Value);
// delay_us(50);
// // HAL_Delay(500);
// s=0,s1=0,s2=0,s3=0;
// Read_Value=0;
// addr=0x001E,Read_Value=0;
// Radd=0x801E,valu=0x000C;
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
// s=HAL_SPI_Transmit(&hspi4, (uint8_t*)&addr, 1, 100);
// s1=HAL_SPI_Transmit(&hspi4,(uint8_t*)&valu, 1, 100);
// //HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);
// printf("1s=%d s=%d W- A=%x, READ_SRAM=%x\n\r",s,s1,addr,valu);
// delay_us(50);
//
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
// s2=HAL_SPI_Transmit(&hspi4, (uint8_t*)&Radd, 1, 100);
// s3=HAL_SPI_Receive(&hspi4,(uint8_t*)&Read_Value,1, 100);
// //HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);
// printf("2s=%d s=%d R-A=%x,V=%x\n\n\r",s2,s3);
// delay_us(50);
//
// s=0,s1=0,s2=0,s3=0;
// Read_Value=0;
//
// addr=0x001E,Read_Value=0;
// Radd=0x801E,valu=0x0001;
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
// s=HAL_SPI_Transmit(&hspi4, (uint8_t*)&addr, 1, 100);
// s1=HAL_SPI_Transmit(&hspi4,(uint8_t*)&valu, 1, 100);
// // HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);
// printf("as=%d s=%d addr=%x, PAT_GEN=%x\n\r",s,s1,addr,valu);
// delay_us(50);
//
// addr=0x001D,Read_Value=0;
// Radd=0x801D,valu=0X0001;
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
// s=HAL_SPI_Transmit(&hspi4, (uint8_t*)&addr, 1, 100);
// s1=HAL_SPI_Transmit(&hspi4,(uint8_t*)&valu, 1, 100);
// HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);
// printf("s=%d s1=%d RAM_UPDATE=%x, V=%x\n\r",s,s1,addr,valu);
// delay_us(50);
//
// printf("end of code=========\n\r");
//
// HAL_GPIO_WritePin(GPIOH,Trigger1_Pin, GPIO_PIN_RESET);
// HAL_Delay(50000);
//
// HAL_GPIO_WritePin(GPIOH,Trigger1_Pin, GPIO_PIN_SET);
////
///////////////////////////////////////////////////////////////////////////////////////////////////////
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Supply configuration update enable
*/
HAL_PWREx_ConfigSupply(PWR_DIRECT_SMPS_SUPPLY);
/** Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1;
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief I2C3 Initialization Function
* @param None
* @retval None
*/
static void MX_I2C3_Init(void)
{
/* USER CODE BEGIN I2C3_Init 0 */
/* USER CODE END I2C3_Init 0 */
/* USER CODE BEGIN I2C3_Init 1 */
/* USER CODE END I2C3_Init 1 */
hi2c3.Instance = I2C3;
hi2c3.Init.Timing = 0x00707CBB;
hi2c3.Init.OwnAddress1 = 0;
hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c3.Init.OwnAddress2 = 0;
hi2c3.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&hi2c3) != HAL_OK)
{
Error_Handler();
}
/** Configure Analogue filter
*/
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c3, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
{
Error_Handler();
}
/** Configure Digital filter
*/
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c3, 0) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN I2C3_Init 2 */
/* USER CODE END I2C3_Init 2 */
}
/**
* @brief SPI4 Initialization Function
* @param None
* @retval None
*/
static void MX_SPI4_Init(void)
{
/* USER CODE BEGIN SPI4_Init 0 */
/* USER CODE END SPI4_Init 0 */
/* USER CODE BEGIN SPI4_Init 1 */
/* USER CODE END SPI4_Init 1 */
/* SPI4 parameter configuration*/
hspi4.Instance = SPI4;
hspi4.Init.Mode = SPI_MODE_MASTER;
hspi4.Init.Direction = SPI_DIRECTION_2LINES;
hspi4.Init.DataSize = SPI_DATASIZE_16BIT;
hspi4.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi4.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi4.Init.NSS = SPI_NSS_SOFT;
hspi4.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
hspi4.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi4.Init.TIMode = SPI_TIMODE_DISABLE;
hspi4.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi4.Init.CRCPolynomial = 0x0;
hspi4.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
hspi4.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
hspi4.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
hspi4.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
hspi4.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
hspi4.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
hspi4.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
hspi4.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
hspi4.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
hspi4.Init.IOSwap = SPI_IO_SWAP_DISABLE;
if (HAL_SPI_Init(&hspi4) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI4_Init 2 */
/* USER CODE END SPI4_Init 2 */
}
/**
* @brief TIM2 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM2_Init(void)
{
/* USER CODE BEGIN TIM2_Init 0 */
/* USER CODE END TIM2_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM2_Init 1 */
/* USER CODE END TIM2_Init 1 */
htim2.Instance = TIM2;
htim2.Init.Prescaler = 200-1;
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
htim2.Init.Period = 0xffff-1;
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM2_Init 2 */
/* USER CODE END TIM2_Init 2 */
}
/**
* @brief USART2 Initialization Function
* @param None
* @retval None
*/
static void MX_USART2_UART_Init(void)
{
/* USER CODE BEGIN USART2_Init 0 */
/* USER CODE END USART2_Init 0 */
/* USER CODE BEGIN USART2_Init 1 */
/* USER CODE END USART2_Init 1 */
huart2.Instance = USART2;
huart2.Init.BaudRate = 115200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart2) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&huart2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART2_Init 2 */
/* USER CODE END USART2_Init 2 */
}
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(CS2_GPIO_Port, CS2_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOH, Trigger2_Pin|Trigger1_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin : CS2_Pin */
GPIO_InitStruct.Pin = CS2_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(CS2_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : Trigger2_Pin Trigger1_Pin */
GPIO_InitStruct.Pin = Trigger2_Pin|Trigger1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
/*Configure GPIO pin : PA0 */
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : CS1_Pin */
GPIO_InitStruct.Pin = CS1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(CS1_GPIO_Port, &GPIO_InitStruct);
}
/* USER CODE BEGIN 4 */
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
Thanks
[edited by: MRD18 at 2:32 PM (GMT -4) on 29 Jun 2023]