This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS1018: Reference Code

Part Number: ADS1018
Other Parts Discussed in Thread: ADS1118

Hello

My customer have some questions about ADS1018,

1.Cann't find address of Conversion Register and Config Register , so how to change Config Register or ready data from Conversion ?

2.Under  ADC mode, My customer write Config Register refer to "8.5.7.1 32-Bit Data Transmission Cycle " , but nothing read

3.Transfer to Temperature Sense Mode, also cann't read data

Is there reference code could be provided ? or it have some indispensable setting to make it work normal ? or time sequence ? or initialization

attached is customer's code

ads1018.c
#include "ads1018.h"
#include "sys.h"
#include "delay.h"
#include "usart.h"


void SPI1_Init(void)
{	
	
	GPIO_InitTypeDef GPIO_InitStructure;
	SPI_InitTypeDef SPI_InitStructure;
	
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_7;//enable PB14/15/13
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //setting PB3/4/5 to push-pull mode
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  //set GPIO speed
	GPIO_Init(GPIOA, &GPIO_InitStructure);//Initical GPIOA 
	
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //���ù���
	GPIO_Init(GPIOA, &GPIO_InitStructure); 
		
	GPIO_SetBits(GPIOA,GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7);  //PA5/6/7����
	
	SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;  //����SPI�������˫�������ģʽ:SPI����Ϊ˫��˫��ȫ˫��
	SPI_InitStructure.SPI_Mode = SPI_Mode_Master;		//����SPI����ģʽ:����Ϊ��SPI
	SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;		//����SPI�����ݴ�С:SPI���ͽ���8λ֡�ṹ
	SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;		//����ͬ��ʱ�ӵĿ���״̬Ϊ�͵�ƽ
	SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;	//����ͬ��ʱ�ӵĵڶ��������أ��������½������ݱ�����
	SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;		//NSS�ź���Ӳ����NSS�ܽţ����������ʹ��SSIλ������:�ڲ�NSS�ź���SSIλ����
	SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;		//���岨����Ԥ��Ƶ��ֵ:������Ԥ��ƵֵΪ256
	SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;	//ָ�����ݴ����MSBλ����LSBλ��ʼ:���ݴ����MSBλ��ʼ
	SPI_InitStructure.SPI_CRCPolynomial = 7;	//CRCֵ����Ķ���ʽ
	SPI_Init(SPI1, &SPI_InitStructure);  //����SPI_InitStruct��ָ���IJ�����ʼ������SPIx�Ĵ���
 
	SPI_Cmd(SPI1, ENABLE); //ʹ��SPI����
	

	ADS1118_ReadVotage(0x62eB);//�������
	delay_ms(8);
}

void ADS1118_Init(void)
{	
  GPIO_InitTypeDef GPIO_InitStructure;
	RCC_APB2PeriphClockCmd(	RCC_APB2Periph_GPIOA, ENABLE );	//PORTFʱ��ʹ�� 

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;  							//PF0 ���� 
 	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  			//�������
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 	GPIO_Init(GPIOA, &GPIO_InitStructure);
 
  ADC_CS_High();																					//CS���ߣ�����������
	SPI1_Init();		   																			//��ʼ��SPI1
	SPI1_SetSpeed(SPI_BaudRatePrescaler_8);									//����Ϊ--Mʱ��,����ģʽ 9MHZʱ��

}

//SPI �ٶ����ú���
//SpeedSet:
//SPI_BaudRatePrescaler_2   2��Ƶ   
//SPI_BaudRatePrescaler_8   8��Ƶ   
//SPI_BaudRatePrescaler_16  16��Ƶ  
//SPI_BaudRatePrescaler_256 256��Ƶ 
  
void SPI1_SetSpeed(u8 SPI_BaudRatePrescaler)
{
  assert_param(IS_SPI_BAUDRATE_PRESCALER(SPI_BaudRatePrescaler));
	SPI1->CR1&=0XFFC7;
	SPI1->CR1|=SPI_BaudRatePrescaler;	//����SPI1�ٶ� 
	SPI_Cmd(SPI1,ENABLE); 

} 

u8 ADS1118_ReadWrite(u8 ConfigReg1)
{
		u8 retry=0;
		while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET) //���ָ����SPI��־λ�������:���ͻ���ձ�־λ
		{
		retry++;
		if(retry>200)return 0;
		}																														
		
	SPI_I2S_SendData(SPI1, ConfigReg1);
		
	while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET) //���ָ����SPI��־λ�������:���ܻ���ǿձ�־λ
		{
		retry++;
		if(retry>200)return 0;
		}	
		
		return SPI_I2S_ReceiveData(SPI1);
}

u32 ADS1118_ReadVotage(u16 ConfigReg)   									//ADS1118���ã�����16λ�������룬
{  
	u8  Hbyte=0;																						//��8λ
	u8  Lbyte=0;																						//��8λ
	u8  Hbyte1=0;																						//��8λ
	u8  Lbyte1=0;			
//	u16 tmp=0;																						//����
  u32 tmp=0;
	
	ADC_CS_Low();                            								//CS����
	delay_us(2);																					//CS�½���SCK��һ����������Ҫ����100ns
	
	Hbyte=	ADS1118_ReadWrite((u8)(ConfigReg>>8));
	Lbyte=  ADS1118_ReadWrite((u8)ConfigReg);
	Hbyte1=	ADS1118_ReadWrite((u8)(ConfigReg>>8));
	Lbyte1=  ADS1118_ReadWrite((u8)ConfigReg);
	tmp=((u16)Hbyte<<24)|((u16)Lbyte<<16)|((u16)Hbyte1<<8)|(u16)Lbyte1;
  	
	delay_us(2);																			//CS????????SCK????????100ns
	ADC_CS_High();                            							//CS??,??????

	return tmp;   																					//??????
}











ads1018.h

  • Fandy,


    I don't think there is specific code for the ADS1018, but there is code available for the ADS1118 which is similar in functionality. If you look up the 430BOOST-ADS1118 there is a download for the 430BOOST-ADS1118 Firmware.

    However, if the customer cannot read out the Conversion or Config Register, I would try to debug the communication by looking at the digital lines and not the code. Use an oscilloscope or logic analyzer to see what comes out of master and ADC. This is far more important than looking at the code to debug the communication. Check the /CS, SCLK, DOUT/DRDY, and DIN lines. The output should look like the lines from Figure 13 or Figure 14.


    Joseph Wu

  • Fandy,

    Has your customer been able to solve their communication problem with the ADS1018? In my last post I gave a link to some firmware that was available. Hopefully, they were able to use that to get things working.

    I'll close this post for now, but if they continue to have problems, post back with more information. Originally I had asked for an oscilloscope photo of the communication, and I'd need that to help with the debug.

    Joseph Wu