AnsweredAssumed Answered

STM32L1 & linear CMOS image sensor

Question asked by cierny.ondrej on Mar 11, 2015
Hi everyone,

I am trying to interface a linear CMOS image sensor by Hamamatsu (S9226-03) with a STM32L1 discovery board, and seek a bit of guidance on how exactly to accomplish that in a suitable way, since I don't have much experience in this area.

The sensor itself is driven by two input signals (see attached datasheet for timing chart):
- a CLK clocking pulse
- a ST (Start) signal to begin scanning
It provides three output analog signals:
- Video, where the actual pixel values are transmitted one after another
- Trig, which is set from high to low when a certain pixel value is ready for reading in the Video signal
- an End of Scan (EOS), signal triggered when the scan is finished

So far, I have been trying to operate it in the following way:
Since the CLK and ST signals need to be sort-of synchronized (datasheet says CLK should be set from high to low only once when ST is low), I have been using a timer with an update interrupt to generate both of the pulses, toggling a GPIO pin in the interrupt handler. I have been using a frequency of 25 kHz for the CLK pulse (timer at 50 kHz), the core is clocked using HSI at 16 MHz.

For the output signals, I thought it would be best to connect the Trigger pin as an external interrupt which would start an ADC conversion on the Video pin each time in the handler was called. Now, the EXTI trigger seems to work fine, counting exactly 1024 calls after starting the scan, but I have problems with getting any reasonable values off the Video pin using ADC.

I am starting a single-scan conversion each time the external interrupt is received and storing the received values in an array of integers, but the values are almost all the same and do not change at all under any light change. I have also connected the EOS signal as another external interrupt to stop the scanning and send values through USART.

Do you have any idea of a more effective way to try to interface it together, or what the problem might be?

Thanks a lot!

PS here are some code snippets:

...
01.__IO unsigned int clk_counter, t_counter;
02.__IO uint16_t sensor_data[1024];
03....
04.// ADC configuration
05.gpio.GPIO_Speed = GPIO_Speed_40MHz;
06.gpio.GPIO_Pin = Vid_Pin;
07.gpio.GPIO_Mode = GPIO_Mode_AN;
08.GPIO_Init(GPIOA, &gpio);
09....
10.ADC_InitTypeDef adc;
11.ADC_StructInit(&adc);
12.adc.ADC_Resolution = ADC_Resolution_8b;
13.ADC_Init(ADC1, &adc);
14.ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 1, ADC_SampleTime_4Cycles);
15. 
16....
17.// Read value from ADC
18.uint16_t get_adc_data()
19.{
20.    uint16_t value;
21.    ADC_SoftwareStartConv(ADC1);
22.    while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
23.    value = ADC_GetConversionValue(ADC1);
24.    ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
25.    return value;
26.}
27. 
28....
29.// Trigger EXTI Interrupt
30.void EXTI1_IRQHandler(void)
31.{
32.    if(EXTI_GetITStatus(EXTI_Line1) != RESET)
33.    {
34.        EXTI_ClearITPendingBit(EXTI_Line1);
35.        // Handle trigger
36.        sensor_data[t_counter] = get_adc_data();
37.        t_counter++;
38.    }
39.}

Attachments

Outcomes