cancel
Showing results for 
Search instead for 
Did you mean: 

How to read the channels of the MCP3208 ADC with SPI STM32F103C8T6 ???

FGRAMOY
Associate

Hello ST community!

I would like to know if someone can help me with my project, I need to read the analog measurements that enter the MCP3208 ADC through SPI with STM32F103C8T6. I need to read all 7 channels of the MCP3208. I've been reading the datasheet and I understand how it works, but I don't know how to program it using HAL libraries in CubeIDE. I have found this link on the web where they do what I want to do, but through Keil C. Could someone help me to do it with HAL APIs?

I would really appreciate the help of the community.

https://vidieukhien.xyz/2018/06/17/tutstm32-keil-c-arm-spi-mcp3208/

Basically I want to translate this code to HAL APIs:

unsigned int MCP3208_Read(char Chanel,char Single) //Single = 1 doc tung kenh,

{

 char first_tran = 0x04;

 char second_tran = 0;

 char first_receive = 0, second_receive = 0;

 Select_Flash();

 first_tran |=(Single&0x01)<<1;                 //Take Singal byte

 first_tran |= ((Chanel&0x04)>>2);              //Take D2 Byte

 second_tran |= (Chanel&0x03)<<6;          //Take D1 D0

 SPI_SendByte(first_tran); //Send first byte

 first_receive = SPI_SendByte(second_tran); //Send second byte to receive MSB byte

 second_receive = SPI_SendByte(0x00);      //Send 0x00 to receive LSB byte

 NotSelect_Flash();

 return (first_receive<<8|second_receive)&0xFFF; 

0 REPLIES 0