cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L1 & linear CMOS image sensor

o23
Associate
Posted on March 11, 2015 at 13:20

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:

...

__IO unsigned

int

clk_counter, t_counter;

__IO uint16_t sensor_data[1024];

...

// ADC configuration

gpio.GPIO_Speed = GPIO_Speed_40MHz;

gpio.GPIO_Pin = Vid_Pin;

gpio.GPIO_Mode = GPIO_Mode_AN;

GPIO_Init(GPIOA, &gpio);

...

ADC_InitTypeDef adc;

ADC_StructInit(&adc);

adc.ADC_Resolution = ADC_Resolution_8b;

ADC_Init(ADC1, &adc);

ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 1, ADC_SampleTime_4Cycles);

...

// Read value from ADC

uint16_t get_adc_data()

{

uint16_t value;

ADC_SoftwareStartConv(ADC1);

while

(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);

value = ADC_GetConversionValue(ADC1);

ADC_ClearFlag(ADC1, ADC_FLAG_EOC);

return

value;

}

...

// Trigger EXTI Interrupt

void

EXTI1_IRQHandler(

void

)

{

if

(EXTI_GetITStatus(EXTI_Line1) != RESET)

{

EXTI_ClearITPendingBit(EXTI_Line1);

// Handle trigger

sensor_data[t_counter] = get_adc_data();

t_counter++;

}

}

0 REPLIES 0