3

I am working on a line scan ccd sensor named TSL2301 .I want to read pixels by USART of stm32f103 but always i just could receive 0xFF , did anybody work with this sensor to help me? I used Usart synchronous mode of STM32f10x , I sent some order to sensor by Usart and want to make 8 clock delay after each order . how can i do it?

int count=0;
int i=0;
uint8_t data[102]={0};
USART_ClockInitStructure.USART_Clock = USART_Clock_Enable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_High;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Enable;
USART_ClockInit(USARTy, &USART_ClockInitStructure);

USART_InitStructure.USART_BaudRate = 2200000;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USARTy, &USART_InitStructure);

/* Configure the USARTy */
USART_Init(USARTy, &USART_InitStructure);

/* Enable the USARTy */
USART_Cmd(USARTy, ENABLE);

while(1)
{
while(count < 3)       
{                                               
USART_SendData(USARTy,0xFF);
while(USART_GetFlagStatus(USARTy, USART_FLAG_TC) == RESET);
count++;
}
count=0;
USART_SendData(USARTy,0x1b);      //RESET command
while(USART_GetFlagStatus(USARTy, USART_FLAG_TC) == RESET);

USART_SendData(USARTy,0x1b);
while(USART_GetFlagStatus(USARTy, USART_FLAG_TC) == RESET);

USART_SendData(USARTy,0x1b);
while(USART_GetFlagStatus(USARTy, USART_FLAG_TC) == RESET);

USART_SendData(USARTy,0x08);  //StartInt Command
while(USART_GetFlagStatus(USARTy, USART_FLAG_TC) == RESET);

while(count < 20 )//DelayIntegrationTime() ;
{
USART_SendData(USARTy,0xFF);
while(USART_GetFlagStatus(USARTy, USART_FLAG_TC) == RESET);
count++;
}
count = 0;  
USART_SendData(USARTy,0x10);    //SampleInt Command
while(USART_GetFlagStatus(USARTy, USART_FLAG_TC) == RESET);

USART_SendData(USARTy,0x02);        //ReadPixel Command
while(USART_GetFlagStatus(USARTy, USART_FLAG_TC) == RESET);

while(count < 2)
{
USART_SendData(USARTy,0xFF);
while(USART_GetFlagStatus(USARTy, USART_FLAG_TC) == RESET);
count++;
}
count = 0;

 USART_Cmd(USARTy, DISABLE);
 USART_ClockInitStructure.USART_CPOL = USART_CPOL_High;
 USART_ClockInitStructure.USART_CPHA = USART_CPHA_1Edge;
 USART_ClockInit(USARTy, &USART_ClockInitStructure);
 USART_Init(USARTy, &USART_InitStructure);
 USART_Cmd(USARTy, ENABLE);

/*read pixels*/
for (i = 0; i < 102; i++) 
{
   while(USART_GetFlagStatus(USARTy, USART_FLAG_RXNE) == RESET);
   data[i] = USART_ReceiveData(USARTy);
   while(count < 1) 
   {
   USART_SendData(USARTy,0xFF);
   while(USART_GetFlagStatus(USARTy, USART_FLAG_TC) == RESET);
   count++;
   }
   count = 0;
 }

 USART_Cmd(USARTy, DISABLE);
 USART_ClockInitStructure.USART_CPOL = USART_CPOL_High;
 USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
 USART_ClockInit(USARTy, &USART_ClockInitStructure);
 USART_Init(USARTy, &USART_InitStructure);
 USART_Cmd(USARTy, ENABLE);

}

Mahtab
  • 107
  • 3
  • 14

1 Answers1

0

There is different USART timing diagrams in STM32F103 reference manual and TAOS datasheet. I think they will not work together in USART mode.

As an Idea, you can try to use UART instead of USART. And clock the device using MCO or other clock source. I think it should work.

It this case all delays you can do with timer.

PS: But there is one more problem you should solve, is to synchronize output of UART with clock source. I need to read stm32 manual more carefuly to tell you how to do it. I'll do it later

picoworm
  • 310
  • 3
  • 13
  • I have a strange solution for you. It should work in theory, but I can't test it. So first the hardware. You should calculate maximum frequency that can accept UART receiver. Is should be about 1MBit/s. Second you must configure timer on this frequency and make clock signal for sensor and also connect it to SPI clk of MCU Yes, you must use SPI to send synchronous data SPI MISO pin should be connected to sensor Serial Input – picoworm Jul 23 '14 at 14:34
  • SPI Must be configured as slave and have 16bit data frame. You have to set SPI register to 0xffff to make IDLE USART output. When you need to send data you must build 1 start bit, than data, then stop bit, this should take 10bits of SPI data register, 6 bit that remains set to 1 – picoworm Jul 23 '14 at 14:43
  • Maybe it is hard to understand. The main idea is use UART only to receive the data. And SPI to send data. You also can try to use SPI clock output and run SPI in master mode. This will work to, but you must always send the FFFF data to generate clock signal – picoworm Jul 23 '14 at 14:46
  • Hope this comments will be useful to you – picoworm Jul 23 '14 at 14:47
  • I recommend you first to work without external peripherals, Use GPIO only with lower frequencies. Try to receive the some information from sensor. Only after that do it with fast hardware shift registers. After all will work you can use DMA on both UART and SPI and free CPU for other tasks – picoworm Jul 23 '14 at 14:59