Sign In

Trouble In Using P10 Module Properly

Dhananjay dhana.ursme@gmail.com India

Hardware: STM32 Discovery Running At 8MHz Software: C On Keil IDE

Sir, I saw your code for the P10 type display in that I'm not able to understand where you are writing data from controller to LED panel. I just found you are writing only to the array and not passing that array to P10 module. Could you please let me know how can I write data line by line(ie., on each row), in my present code I'm only able to write data on every 4th row.

Images

Program

#include "stm32f30x.h"
#include "stm32f30x_conf.h"
#include "stm32f30x_rcc.h"
#include "stm32f30x_gpio.h"
#include "stm32f30x_spi.h"
#include "stm32f30x_tim.h"
#include "DJ_fonts.h"
#include <stdint.h>
#define A_line_high GPIOE->BSRR |=GPIO_Pin_8
#define B_line_high GPIOE->BSRR |=GPIO_Pin_9
#define A_line_low GPIOE->BRR |= GPIO_Pin_8
#define B_line_low GPIOE->BRR |= GPIO_Pin_9
#define Shift_clk_low GPIOE->BRR |= GPIO_Pin_10
#define Shift_clk_high GPIOE->BSRR |= GPIO_Pin_10
#define OE_line_high GPIOE->BSRR |= GPIO_Pin_11
#define OE_line_low GPIOE->BRR |= GPIO_Pin_11
#define serial_data_low GPIOE->BRR |= GPIO_Pin_12
#define serial_data_high GPIOE->BSRR |= GPIO_Pin_12
#define store_clock_high GPIOE->BSRR |= GPIO_Pin_13
#define store_clock_low GPIOE->BRR |= GPIO_Pin_13
SPI_InitTypeDef SPI_2_initstruct;
GPIO_InitTypeDef GPIO_Init_portE,GPIOB_initstruct;
#define DELAY 900000
uint32_t val=DELAY;uint8_t int_syc=0;
extern font_det ms_sanserif11;

void DJ_SPI_Send(uint8_t data2)
	{
		data2=~data2;
		SPI_SendData8(SPI2,data2);                      //SPI_SendData8(SPI1,data2);
		while(!((SPI2->SR) & (1<<1)));                  //while(!((SPI1->SR) & (1<<1)));
							
	}
void SPI_init(void)
	{
		SPI_I2S_DeInit(SPI2);    //Disable SPI
		RCC->AHBENR |= (RCC_AHBENR_GPIOBEN);
		RCC->APB1ENR |=RCC_APB1ENR_SPI2EN;  //clock for the spi2
		GPIOB_initstruct.GPIO_Pin = (GPIO_Pin_13 |GPIO_Pin_14 |GPIO_Pin_15);
		GPIOB_initstruct.GPIO_Mode =GPIO_Mode_AF;  //Setting PA5-PA6-PA7 on alternate function
		GPIOB_initstruct.GPIO_PuPd= GPIO_PuPd_NOPULL ;
		GPIOB_initstruct.GPIO_Speed = GPIO_Speed_Level_3 ;
		GPIOB_initstruct.GPIO_OType = GPIO_OType_PP;
		GPIO_Init(GPIOB,&GPIOB_initstruct);
		GPIOB->AFR[1] = 0x55500000;
		SPI_2_initstruct.SPI_Direction= SPI_Direction_2Lines_FullDuplex;
		SPI_2_initstruct.SPI_Mode=SPI_Mode_Master;
		SPI_2_initstruct.SPI_DataSize=SPI_DataSize_8b;
		SPI_2_initstruct.SPI_CPOL=SPI_CPOL_Low;
		SPI_2_initstruct.SPI_CPHA=SPI_CPHA_1Edge;
		SPI_2_initstruct.SPI_NSS=SPI_NSS_Soft;
		SPI_2_initstruct.SPI_BaudRatePrescaler=SPI_BaudRatePrescaler_2;
		SPI_2_initstruct.SPI_FirstBit=SPI_FirstBit_MSB;
		SPI_2_initstruct.SPI_CRCPolynomial=7;
		SPI_Init( SPI2, &SPI_2_initstruct);
		SPI_Cmd(SPI2,ENABLE);
	}  
void PWM_init(){
	TIM_TimeBaseInitTypeDef timer_PWM_stuct;
	TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  TIM_OCInitTypeDef TIM_OCInitStructure;
	RCC->APB2ENR |=RCC_APB2ENR_TIM1EN;
	GPIO_PinAFConfig(GPIOB, GPIO_PinSource0,GPIO_AF_6);

 
  TIM_TimeBaseStructure.TIM_Prescaler = 8 - 1; // 72 to 1 MHz
  TIM_TimeBaseStructure.TIM_Period = 1000 - 1; // 1 MHz to 1 KHz
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 
  TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
 
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = 1000 / 4; // 25%
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
 
  TIM_OC1Init(TIM1, &TIM_OCInitStructure);
  TIM_OC2Init(TIM1, &TIM_OCInitStructure);
  TIM_OC3Init(TIM1, &TIM_OCInitStructure);
}

void LED_functionality_init()
{
	store_clock_low;
	A_line_low;
	B_line_low;
	OE_line_high;
	serial_data_high;
	Shift_clk_low;
}
void write_function(char data)
{

switch (int_syc)   
{
case 0:
     OE_line_low;DJ_SPI_Send(data);
     A_line_low;B_line_low;OE_line_high;
     break;
case 1:
     OE_line_low;DJ_SPI_Send(data);
     A_line_high;B_line_low;OE_line_high;
     break;
case 2:
     OE_line_low;DJ_SPI_Send(data);
     A_line_low;B_line_high;OE_line_high;
     break;
case 3:
     OE_line_low;DJ_SPI_Send(data);
     A_line_high;B_line_high;OE_line_high;
     break;
}
int_syc++;if(int_syc>3)int_syc=0;
		store_clock_high;
		store_clock_low;
}
void data_to_LED(char data)
{
	char i=0,j=0;
	for(;i<8;i++){
		if(data & 1<<(7-i)) {
			serial_data_low;
			Shift_clk_high;
			for(j=0;j<3;j++);
			Shift_clk_low;
		}
		else {
			serial_data_high;
			Shift_clk_high;
			for(j=0;j<3;j++);
			Shift_clk_low;
		}
			store_clock_high;
			store_clock_low;
			A_line_high;
			B_line_high;
			OE_line_low;
			A_line_low;
			B_line_low;
	}
}

int main(){
	char j,x=0;
	unsigned char i=0,arr[8]={0xFE,0xFC,0xF8,0xF0,0xE0,0xC0,0x80,0x00};
	RCC->AHBENR |= (1<<21);
	
	GPIO_Init_portE.GPIO_Pin= (GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
	GPIO_Init_portE.GPIO_Mode= GPIO_Mode_OUT;
	GPIO_Init_portE.GPIO_Speed=GPIO_Speed_Level_2;
	GPIO_Init_portE.GPIO_PuPd=GPIO_PuPd_NOPULL;
	GPIO_Init_portE.GPIO_OType=GPIO_OType_PP;
	GPIO_Init(GPIOE,&GPIO_Init_portE);
	SPI_init();
	LED_functionality_init();
				for(j=0;j<16;j++){
					DJ_SPI_Send(0x00);
					store_clock_high;
					store_clock_low;
				}
				
	while(1){
		
			for(j=0;j<=8;j++)
			{
				{
					write_function(arr[j]);
				}
			}
	}
}

Replies

R Avinash
2016-08-26 12:21:02
From where did you get this code?
R Dhananjay
2016-08-27 07:42:59
You can close this thread, I solved it.

Post a reply to Dhananjay

Think you can help Dhananjay ? Then post your thoughts that might help Dhananjay. You will earn a lot of reputation in the technical community.

If your program is in multiple files, then ZIP the entire folder and attach below

Images and Screenshots

These helps other better understand your suggestion.