Stm32 driver 12bit ad TLC2543 (I/O simulation mode)

Source: Internet
Author: User

 

/*************************************** **************************************** ***********
* File name: tlc2543.c
* Copyright:
* Module name: TLC2543 driver
* CPU: stm32f103rct6 clock speed: 72 m
* Author:
* Creation date:
* Function Overview:
* ---------------------------------------- Modification history ------------------------------------------
* Current version: modifier: modification date:
* Modification description:
**************************************** **************************************** **********/

# Include "cmdlib \ stm32f10x. H"
# Include "Hal. H"

# Define tlc2543_sck_h gpiob-> bsrr = gpio_pin_15
# Define tlc2543_sck_l gpiob-> BRR = gpio_pin_15

# Define tlc2543_si_h gpioc-> bsrr = gpio_pin_6
# Define tlc2543_si_l gpioc-> BRR = gpio_pin_6

# Define tlc2543_cs_h gpioc-> bsrr = gpio_pin_8
# Define tlc2543_cs_l gpioc-> BRR = gpio_pin_8

# Define tlc2543_so_h gpioc-> bsrr = gpio_pin_7
# Define tlc2543_so_l gpioc-> BRR = gpio_pin_7
# Define tlc2543_so_read gpioc-> IDR & gpio_pin_7
// # Define tlc2543_so_read1 gpioc-> ODR & gpio_pin_7

/*************************************** **************************************** ***********
* Function name: tlc2543_gpio_config
* Function description:
* Parameter: Parameter Name: input/output? Type description
*
* Return value:
* Author:
* Creation date:
* Global variables:
* Global static variables:
* Local static variables:
* ---------------------------------------- Modification history ------------------------------------------
* Current version: modifier: modification date:
* Modification description:
**************************************** **************************************** **********/
Void tlc2543_gpio_config (void)
{
Gpio_inittypedef gpio_initstructure;

Gpio_initstructure.gpio_pin = gpio_pin_6 | gpio_pin_8;
Gpio_initstructure.gpio_speed = gpio_speed_50mhz;
Gpio_initstructure.gpio_mode = gpio_mode_out_pp;
Gpio_init (gpioc, & gpio_initstructure );

Gpio_initstructure.gpio_pin = gpio_pin_7;
Gpio_initstructure.gpio_speed = gpio_speed_50mhz;
Gpio_initstructure.gpio_mode = gpio_mode_ipu;
Gpio_init (gpioc, & gpio_initstructure );

Gpio_initstructure.gpio_pin = gpio_pin_15;
Gpio_initstructure.gpio_speed = gpio_speed_50mhz;
Gpio_initstructure.gpio_mode = gpio_mode_out_pp;
Gpio_init (gpiob, & gpio_initstructure );
}
/*************************************** **************************************** ***********
* Function name: delay_ad
* Function description:
* Parameter: Parameter Name: input/output? Type description
*
* Return value:
* Author:
* Creation date:
* Global variables:
* Global static variables:
* Local static variables:
* ---------------------------------------- Modification history ------------------------------------------
* Current version: modifier: modification date:
* Modification description:
**************************************** **************************************** **********/
Void delay_ad (volatile u32 time)
{
2010i;
While (Time --)
{
For (I = 0; I <8; I ++ );
}
}

/*************************************** **************************************** ***********
* Function name: getchannelval
* Function description:
* Parameter: Parameter Name: input/output? Type description
*
* Return value:
* Author:
* Creation date:
* Global variables:
* Global static variables:
* Local static variables:
* ---------------------------------------- Modification history ------------------------------------------
* Current version: modifier: modification date:
* Modification description:
**************************************** **************************************** **********/
B2getchannelval (u8 port)
{
U8 I;
U8 ucsend = port;
2010adval = 0;

If (Port> 0x0f)
Return 0;
Delay_active (600 );
Tlc2543_sck_l;
Delay_ad (6 );
Tlc2543_cs_l;
Delay_ad (6 );
Ucsend <= 4;
For (I = 0; I <12; I ++)

{

If (tlc2543_so_read )! = 0)
Adval | = 1; // table [I];
Else
Adval | = 0;

If (ucsend & 0x80 )! = 0)
Tlc2543_si_h;
Else
Tlc2543_si_l;
Delay_ad (6 );
Tlc2543_sck_h;
Delay_ad (6 );
Tlc2543_sck_l;

Ucsend <= 1;
Adval <= 1;
}

Delay_ad (6 );
Tlc2543_cs_h;
Adval> = 1;
Return (adval );
}

/*************************************** **************************************** ***********
* Function name: read2543
* Function description:
* Parameter: Parameter Name: input/output? Type description
*
* Return value:
* Author:
* Creation date:
* Global variables:
* Global static variables:
* Local static variables:
* ---------------------------------------- Modification history ------------------------------------------
* Current version: modifier: modification date:
* Modification description:
**************************************** **************************************** **********/
Extern 2010alogval [11];
Void read2543 (void)
{
2010i;
For (I = 0; I <12; I ++)
{
Alogval [I] = getchannelval (I );
Invalid ickdelay (50 );
}
}
/*************************************** **************************************** ***********
* Function name: calc_ad_value
* Function Description: Computing of data collected by AD
* Parameter: Parameter Name: input/output? Type description
* Ch --- ad channel N --- partial pressure multiple
* Return value:
* Author:
* Creation date:
* Global variables:
* Global static variables:
* Local static variables:
* ---------------------------------------- Modification history ------------------------------------------
* Current version: V2 modifier: zds modification date:
* Modification description:
**************************************** **************************************** **********/
2010calc_ad_value (u8 CH, u8 N)
{
2010ad;
U8 Buf [4];
Float VDC;
2010i;

Buf [3] = (u8) (alogval [CH] % 10) + 0x30;
Alogval [CH] = alogval [CH]/10;
 
Buf [2] = (u8) (alogval [CH] % 10) + 0x30;
Alogval [CH] = alogval [CH]/10;

Buf [1] = (u8) (alogval [CH] % 10) + 0x30;
Alogval [CH] = alogval [CH]/10;

Buf [0] = (u8) (alogval [CH] % 10) + 0x30;
Alogval [CH] = alogval [CH]/10;

AD = atoi (BUF );
VDC = N * 5 * Ad/4096.0;
I = VDC * 100;
Return I;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.