cancel
Showing results for 
Search instead for 
Did you mean: 

SPI not working with MCP6S21

MJouv
Associate

Hi everyone,

I would like to use a simple VGA (MCP6S21) but still not reach to do it.

The datasheet is available here : http://ww1.microchip.com/downloads/en/devicedoc/21117b.pdf

I'd like to put a +2 gain, the signals (SCK,MOSI) I transmit seems to be OK but the gain is still +1.

I also but on and off CS signal.

Here is my SPI init code ( generated with STM32CubeMX) :

void MX_SPI3_Init(void)

{

 hspi3.Instance = SPI3;

 hspi3.Init.Mode = SPI_MODE_MASTER;

 hspi3.Init.Direction = SPI_DIRECTION_2LINES;

 hspi3.Init.DataSize = SPI_DATASIZE_8BIT;

 hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;

 hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;

 hspi3.Init.NSS = SPI_NSS_SOFT;

 hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;

 hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;

 hspi3.Init.TIMode = SPI_TIMODE_DISABLE;

 hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

 hspi3.Init.CRCPolynomial = 7;

 hspi3.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;

 hspi3.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;

 if (HAL_SPI_Init(&hspi3) != HAL_OK)

 {

  Error_Handler();

 }

}

and my main code :

int main(void)

{

 /* USER CODE BEGIN 1 */

 /* USER CODE END 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 SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_SPI3_Init();

 MX_USART2_UART_Init();

 /* USER CODE BEGIN 2 */

 uint8_t data[2];

 data[0]=(uint8_t) WRITE; //0x40

 data[1]=(uint8_t) GAIN_2; //0x01

 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_11,GPIO_PIN_SET);

 HAL_Delay(100);

 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_11,GPIO_PIN_RESET);

 while (HAL_SPI_Transmit(&hspi3,(uint8_t *)data,(uint16_t)sizeof(data),1000)!=HAL_OK);

 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_11,GPIO_PIN_SET);

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

}

If someone could help me, I would really appreciate :)

0 REPLIES 0